这是我自定义按钮的当前方式:
UIAlertView *av = [[UIAlertView alloc] init];
[av addButtonWithTitle:@""];
UIButton *yesButton = [av.subviews lastObject];
[av show];
[yesButton setImage:[UIImage imageNamed:@"test.png"] forState:UIControlStateNormal];
这样做的问题是,原始视图在我为按钮设置的图像周围仍然可见。它没有完全封装图像。这是我到目前为止所拥有的示例:
https://www.dropbox.com/s/htb9pfihwmel5oo/testimage.png https://www.dropbox.com/s/htb9pfihwmel5oo/testimage.png
有没有办法让图像完全占据整个按钮?
如果您不需要像 Sly Raskal 的答案那样强大的东西,而只是想要快速破解,那么它的工作原理与您现有的代码类似。你可以做这样的事情......当然,你可以更改新的按钮框架以匹配你想要的方式。另外,您必须将 UIAlertView 定义为变量,以便您可以引用它,并在 someAction: 方法中将其关闭。
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];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)