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 上的按钮
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
