Customizing the buttons on a UIAlertView(自定义 UIAlertView 上的按钮)
问题描述
这是我自定义按钮的当前方式:
This is the current way i'm customizing my buttons:
UIAlertView *av = [[UIAlertView alloc] init];
[av addButtonWithTitle:@""];
UIButton *yesButton = [av.subviews lastObject];
[av show];
[yesButton setImage:[UIImage imageNamed:@"test.png"] forState:UIControlStateNormal];
这样做的问题是原始视图在我为按钮设置的图像周围仍然可见.它没有完全封装图像.这是我到目前为止的一个例子:
The problem with this is that the original view is still visible around the image I set for the button. It doesn't completely encapsulate the image. Here's an example of what I have so far:
https://www.dropbox.com/s/htb9pfihwmel5oo/testimage.png
有没有办法让图片完全占据整个按钮?
Is there anyway to make it so that the image completely takes up the entire button?
推荐答案
如果您不想要像 Sly Raskal 的答案那样健壮的东西,并且只想快速破解,那么它的工作方式类似于您现有的代码.你可以做这样的事情..当然你可以改变新的按钮框架来匹配你想要的.此外,您必须将 UIAlertView 定义为一个变量,以便您可以引用它,并在您的 someAction: 方法中将其关闭.
If you wan't something that's not as robust as Sly Raskal's answer and just want a quick hack, that works similar to your existing code. You could do something like this..Of course you can change the new buttons frame to match how you want it. Also, you would have to define the UIAlertView as a variable to so you have a reference to it, and dismiss it in your someAction: method.
UIAlertView *av = [[UIAlertView alloc] init];
[av addButtonWithTitle:@""];
UIButton *yesButton = [av.subviews lastObject];
[yesButton setHidden:YES];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[av addSubview:button];
[av show];
[button setImage:[UIImage imageNamed:@"test.png"] forState:UIControlStateNormal];
[button addTarget:av action:@selector(someAction:) forControlEvents:[yesButton allControlEvents]];
[button setFrame:yesButton.frame];
这篇关于自定义 UIAlertView 上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自定义 UIAlertView 上的按钮


基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01