自定义UIAlertView上的按钮 [英] Customizing the buttons on a UIAlertView

查看:59
本文介绍了自定义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上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆