正确绘制我子类的UIAlertView中如下:子类UIAlertView中没有的iOS 4.2
@interface NarrationAlertView : UIAlertView {
UIImage * backgroundImage; //The image I want as custom background
UILabel * textualNarrationView; //The test I wanna be displayed on the view
}
并实现了这种方式:
- (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 {
/* Here I draw the image as background */
CGSize imageSize = self.backgroundImage.size;
[self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
}
- (void)layoutSubviews {
/* To fit the text */
[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{
/* Showing the view */
[super show];
CGSize imageSize = self.backgroundImage.size;
self.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height);
}
在iOS上的以前的版本(我总是在模拟器上测试)子类运行良好,并在显示时显示正确绘制的自定义背景图像,并且就是其上的文本,而在4.2版本中,它绘制了UIAlertView经典背景(蓝色圆角矩形)顶部我的形象。
我在做什么错?不胜感激任何有关UIAlertView编程和UIView的建议。
UPDATE是否有人有一些UIAlertView替换类共享?
我担心的是,你怎么样完成的弹出效果与背景阴影视景? – rano 2010-11-24 20:01:31
实际上,我们对UI采取了不同的方式,过去的弹出窗口现在从屏幕顶部向下滑动/向上滑动。我确实研究了复制弹出效果,并发现这个有用的链接:http://delackner.com/blog/2009/12/mimicking-uialertviews-animated-transition/ – 2010-11-24 20:04:30