Subclassed UIAlertView not drawn correctly in iOS 4.2

前端 未结 3 561
北海茫月
北海茫月 2021-01-07 01:16

I\'ve subclassed an UIAlertView as follow:

@interface NarrationAlertView : UIAlertView {
    UIImage * backgroundImage; //The image I want as custom backgro         


        
相关标签:
3条回答
  • 2021-01-07 02:07

    We had a similar problem with UIAlertView in iOS 4.2; we were customizing the layout, added text boxes and rearranging the buttons.

    This won't be a popular answer, but due to the changes to UIAlertView, we had to abandon using it entirely for this purpose. We always knew it was a fragile implementation since customizing/subclassing UIAlertView isn't officially supported and makes assumptions about the internal structure of the view hierarchy, but the release of 4.2 really kicked us into gear.

    In the end, we implemented our own UI element to replace the customized UIAlertView.

    0 讨论(0)
  • 2021-01-07 02:17

    Prior to iOS 4.2 UIAlertView's standard dark blue rounded rectangle was drawn in drawRect. the rounded rectangle could be removed by subclassing UIAlertView and implementing drawRect without calling super. however in 4.2 the rounded rectangle is a UIImageView subview. the quick, easy (not best) solution: If you are not adding any UIImageView instances to your UIAlertView subclass you can simply remove the default UIImageView that is loaded by observing subview additions:

    - (void)didAddSubview:(UIView *)subview {
      if ([subview isMemberOfClass:[UIImageView class]]) {
        [subview removeFromSuperview];
      }
    }
    
    0 讨论(0)
  • 2021-01-07 02:20

    I got burned by this too. I ended up writing a replacement class, which I'm sharing on github:

    https://github.com/TomSwift/TSAlertView

    0 讨论(0)
提交回复
热议问题