iphone - UIActionSheet 按钮的颜色

标签 iphone cocoa-touch uikit

如何更改 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/

相关文章:

iphone - 如何从 iPhone 中的 .DBF 文件中获取数据

iphone - 如何以编程方式暂停 NSTimer?

ios - 如何测量渲染字符串的实际高度?

ios - UIButton:使点击区域大于默认点击区域

ios - 自定义 UI 导航栏和按钮

swift - 如何像第一次在 Swift 中一样重新加载 View Controller ?

java - JSON:拒绝来自第三方的服务器请求

iphone - XCODE 4.2 中的构建文件夹位置

iphone - 从 CVPixelBuffer Reference 获取所需数据

iphone - UITableView,让页脚停留在屏幕底部?