Subclassed UIAlertView not drawn correctly in iOS 4.2

前端 未结 3 593
北海茫月
北海茫月 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: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];
      }
    }
    

提交回复
热议问题