gpt4 book ai didi

iphone - 子类 UIAlertView 在 iOS 4.2 中未正确绘制

转载 作者:行者123 更新时间:2023-12-03 20:22:23 26 4
gpt4 key购买 nike

我对 UIAlertView 进行了子类化,如下所示:

@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 的建议都将受到赞赏。

更新有人有一些 UIAlertView 替换类可以分享吗?

最佳答案

我们在 iOS 4.2 中的 UIAlertView 也遇到了类似的问题;我们正在自定义布局,添加文本框并重新排列按钮。

这不会是一个受欢迎的答案,但由于 UIAlertView 的更改,我们不得不完全放弃将其用于此目的。我们一直都知道这是一个脆弱的实现,因为自定义/子类化 UIAlertView 不受官方支持,并且对 View 层次结构的内部结构做出了假设,但 4.2 的发布确实让我们开始行动。

最终,我们实现了自己的 UI 元素来替换定制的 UIAlertView。

关于iphone - 子类 UIAlertView 在 iOS 4.2 中未正确绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4269461/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com