iOS:自定义 UIAlertView 无法正常工作

发布于 2024-12-11 05:27:10 字数 542 浏览 0 评论 0原文

在此链接中

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾铮苏瑾 2024-12-18 05:27:10

我不会尝试使用 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.

美男兮 2024-12-18 05:27:10

使用此自定义类创建自定义警报视图没有任何问题。

创建一个类及其头文件,并将上面 URL 中的代码粘贴到每个 .m.h 文件中。将它们导入到您的项目中,然后将头文件导入到警报视图所在的类中。

#import "ProAlertView.h"

然后在需要的地方调用它。这是我用来调用自定义警报视图的方法:

- (void)processHasErrors
{
//Due to internet connection or server error.
ProAlertView *alert = [[ProAlertView alloc] initWithTitle:NO_CONNECTION_ALERT_TITLE message: NO_CONNECTION_ALERT_MESSAGE delegate:self cancelButtonTitle:NO_CONNECTION_ALERT_VIEW_DISMISS_BUTTON otherButtonTitles:nil];

[alert setBackgroundColor:[UIColor colorWithRed:0.07 green:0.19 blue:0.35 alpha:0.8] withStrokeColor: 
 [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];


[alert show];
[activityIndicator stopAnimating];
}

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.

#import "ProAlertView.h"

and then call it where-ever you need. This is the method I've used to call the customized alert view:

- (void)processHasErrors
{
//Due to internet connection or server error.
ProAlertView *alert = [[ProAlertView alloc] initWithTitle:NO_CONNECTION_ALERT_TITLE message: NO_CONNECTION_ALERT_MESSAGE delegate:self cancelButtonTitle:NO_CONNECTION_ALERT_VIEW_DISMISS_BUTTON otherButtonTitles:nil];

[alert setBackgroundColor:[UIColor colorWithRed:0.07 green:0.19 blue:0.35 alpha:0.8] withStrokeColor: 
 [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];


[alert show];
[activityIndicator stopAnimating];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文