这是我自定义按钮的当前方式:
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 上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!