如何更改UIActionSheet按钮的颜色?
发布于 2012-01-13 22:54:24
我已经创建了子类UICustomActionSheet,它允许在UIActionSheet中自定义按钮的字体、颜色和图像。这对于appstore来说是绝对安全的,你可以在下面的链接中找到这个类的代码:
https://github.com/gloomcore/UICustomActionSheet
尽情享受吧!
发布于 2010-11-23 01:45:45
不幸的是,如果不使用未公开的API,就没有正式的方法来更改UIActionSheet上按钮的颜色。如果将UIActionSheet控件派生为子类,则可以对其进行自定义。
请参阅此示例:http://blog.corywiles.com/customizing-uiactionsheet-buttons
发布于 2013-02-07 12:53:03
我们可以使用背景图像来做到这一点。我认为这是最简单的方法。
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Actionsheet" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet addButtonWithTitle:@"Button 1"]; //Blue color
[actionSheet addButtonWithTitle:@"Button 2"];
[actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet addButtonWithTitle:nil];
[actionSheet setCancelButtonIndex:2];
[actionSheet setDestructiveButtonIndex:1];
[actionSheet showInView:self.view];
UIButton *button = [[actionSheet subviews] objectAtIndex:1];
UIImage *img = [button backgroundImageForState:UIControlStateHighlighted];//[UIImage imageNamed:@"alert_button.png"];
[button setBackgroundImage:img forState:UIControlStateNormal];
https://stackoverflow.com/questions/4248400
复制相似问题