iOS:自定义 UIAlertView 无法正常工作
在此链接中
http://joris.kluivers.nl/iphone-dev/?p= CustomAlert
有一个自定义警报视图的示例,但它不能正常工作,因为它具有警报视图的经典矩形。 在这个链接中写道: 要将外观从默认更改为我们自己的背景图像,需要重写drawRect:。我们不调用超级drawRect方法来阻止UIAlertView绘制默认外观。我们所做的就是绘制背景图像。
- (void) drawRect:(CGRect)rect {
// do not call the super drawRect
CGSize imageSize = self.backgroundImage.size;
[self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
}
但它还不起作用。
in this link
http://joris.kluivers.nl/iphone-dev/?p=CustomAlert
there is a sample of a custom alert view but it don't work fine because it have evere its classic rect of alertView.
In this link is written that:
To change the appearance from the default to our own background image drawRect: needs to be overridden. We do not call the super drawRect method to prevent UIAlertView from drawing the default appearance. All we do is draw our background image.
- (void) drawRect:(CGRect)rect {
// do not call the super drawRect
CGSize imageSize = self.backgroundImage.size;
[self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
}
but it don't work yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不会尝试使用 UIAlertView 做类似的事情。
我会创建一个自定义 UIView 并在您想要显示消息时将其添加到您的视图中。
I wouldn't try to do something like that using a UIAlertView.
I'd make a custom UIView and add that to your View when you want to display the message.
使用此自定义类创建自定义警报视图没有任何问题。
创建一个类及其头文件,并将上面 URL 中的代码粘贴到每个
.m
和.h
文件中。将它们导入到您的项目中,然后将头文件导入到警报视图所在的类中。然后在需要的地方调用它。这是我用来调用自定义警报视图的方法:
Use this custom class to create a customized alert view without any issues.
Create a class with its header file, and paste the code from the URL above to each of
.m
and.h
files. Import them into your project, and then import the header file into the class you the alert view for.and then call it where-ever you need. This is the method I've used to call the customized alert view: