带有自定义按钮的自定义 UIAlertView

发布于 2024-11-16 18:07:49 字数 352 浏览 1 评论 0原文

我需要显示一个自定义 UIAlertView,它将有一个图像作为背景和两个自定义按钮,这将不是常规的 UIAlertView 按钮。这些按钮也将被定制,并有自己的艺术品。

Sample AlertView

上面的示例有一个背景,但我还想在其上添加自定义按钮。

我正在遵循指南,但我认为它没有解决自定义问题按钮处理。

怎么做呢?有什么想法吗?

I need to show a Custom UIAlertView which is going to have an image as a background and two Custom Buttons which will be not the regular UIAlertView Buttons. These buttons will be customized as well and would have their own Artwork.

Sample AlertView

The example above has a background but I also want to add Custom Button on it.

I am following this guide but I don't think it address the Custom Button handling.

How to do that? Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

笑着哭最痛 2024-11-23 18:07:49

苹果似乎不喜欢你过度定制 UIAlertView,我听说过很多次他们因此拒绝了应用程序进入应用程序商店。

由于您所追求的自定义程度,我建议您创建自己的新警报类,该类具有动画效果并具有背景阴影等,并带有可以自定义其位置/外观的按钮。

Apple doesn't appear to like you overly-customising UIAlertView, and I've heard of a number of occasions where they've declined an app going into the app store because of it.

Because of the extent of customisation you're after, I suggest you create your own new Alert class that animates in and has a background shadow etc with buttons that you can customise the location/look of.

不爱素颜 2024-11-23 18:07:49

我发现 Jeff LaMarche 的这篇博客文章对于制作自定义警报视图非常有帮助:http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html。他完成了创建自定义类的步骤,因为修改 UIAlertView 可能会导致 App Store 拒绝(但是他警告说,使用自定义技术仍然会导致 HIG 违规,但我怀疑它们会导致您想要做的事情)。完成后,您将拥有一个自定义警报视图类,可以以与 UIAlertView 大致相同的样式添加它:

至此,我们就完成了。我们现在可以
完全使用此自定义警报视图
我们使用 UIAlertView 的方式相同:

CustomAlertView *alert = [[CustomAlertView alloc] init];
警报.委托=自我;
[警报显示];
[警报发布];

他创建一个自定义文本输入视图。显然,在您的情况下,您可能希望使用不同的背景,而不是添加文本字段,而是只使用按钮。由于他也在他的视图中制作了自定义按钮,因此它应该可以满足您的所有需求,甚至更多。

I found this blog post by Jeff LaMarche to be really helpful in making custom alert views: http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html. He goes through the steps of making a custom class since modifying UIAlertView can cause App Store rejection (however he warns that using custom techniques can still cause HIG violations, but I doubt they will for what you're trying to do). By the time you're done, you'll have a custom alert view class that can be added in much the same style as UIAlertView:

At this point, we're done. We can now
use this custom alert view exactly the
same way we use UIAlertView:

CustomAlertView *alert = [[CustomAlertView alloc] init];
alert.delegate = self;
[alert show];
[alert release];

He creates a custom text input view. Obviously, in your case, you would want to use a different background and instead of adding a text field you'd stick to just the buttons. Since he makes custom buttons in his view too it should cover all your needs, if not more.

痴情换悲伤 2024-11-23 18:07:49

不幸的是苹果不允许子类化 UIAlertView:

UIAlertView 类旨在按原样使用,而不是
支持子类化。该类的视图层次结构是私有的并且
不得修改。

最简单的方法是创建您自己的具有类似行为的类。

这是一个例子:
http://iosdevtricks.blogspot.com/2013 /04/creating-custom-alert-view-for-iphone.html

Unfortunately Apple does not allow subclassing UIAlertView:

The UIAlertView class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified.

The easiest way would be to create your own class with similar behavior.

Here's an example:
http://iosdevtricks.blogspot.com/2013/04/creating-custom-alert-view-for-iphone.html

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