I have subclassed UIAlertView as follows:
@interface NarrationAlertView : UIAlertView {
UIImage * backgroundImage;
UILabel * textualNarrationView;
}
And implemented as follows:
- (id)initNarrationViewWithImage:(UIImage *)image{
if (self = [super init]){
UILabel * alertTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.textualNarrationView = alertTextLabel;
[alertTextLabel release];
[self addSubview:alertTextLabel];
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGSize imageSize = self.backgroundImage.size;
[self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
}
- (void)layoutSubviews {
[textualNarrationView sizeToFit];
CGRect textRect = textualNarrationView.frame;
textRect.origin.x = (CGRectGetWidth(self.bounds) - CGRectGetWidth(textRect)) / 2;
textRect.origin.y = (CGRectGetHeight(self.bounds) - CGRectGetHeight(textRect)) / 2;
textRect.origin.y -= 70;
textualNarrationView.frame = textRect;
}
- (void)show{
[super show];
CGSize imageSize = self.backgroundImage.size;
self.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height);
}
In previous versions of iOS (I always tested on the simulator), the subclass worked fine, and when it was shown, it displayed a correctly configured background image and only text , whereas in 4.2, it draws the classic UIAlertView background (blue rounded rectangle) on top of mine Images.
What am I doing wrong? Any suggestion on programming UIAlertView and UIView will also be appreciated.
UPDATE . Does anyone have a UIAlertView replacement class to share?