如何更改 UIActionSheet 按钮的颜色?
最佳答案
iOS 8 (UIAlertController)
如果您使用 UIAlertController,则非常简单。只需更改 UIAlertController View 上的色调颜色即可。
[alertController.view setTintColor:[UIColor red];
iOS 7 (UIActionSheet)
我使用这个简单的方法成功地更改了文本颜色。
- (void) changeTextColorForUIActionSheet:(UIActionSheet*)actionSheet {
UIColor *tintColor = [UIColor redColor];
NSArray *actionSheetButtons = actionSheet.subviews;
for (int i = 0; [actionSheetButtons count] > i; i++) {
UIView *view = (UIView*)[actionSheetButtons objectAtIndex:i];
if([view isKindOfClass:[UIButton class]]){
UIButton *btn = (UIButton*)view;
[btn setTitleColor:tintColor forState:UIControlStateNormal];
}
}
}
确保在您调用之后运行
[actionSheet showInView];
如果在[showInView]之前调用它,则除取消按钮之外的所有按钮都将被着色。希望这对某人有帮助!
关于iphone - UIActionSheet 按钮的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4248400/