UIActionSheet按钮的颜色

Abh*_*nav 16 iphone cocoa-touch uikit

如何更改UIActionSheet按钮颜色的颜色?

Rym*_*nel 34

iOS 8(UIAlertController)

如果您正在使用UIAlertController,这非常简单.只需更改UIAlertController视图上的色调颜色即可.

[alertController.view setTintColor:[UIColor red];
Run Code Online (Sandbox Code Playgroud)

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];

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

确保在打电话运行此功能

[actionSheet showInView];
Run Code Online (Sandbox Code Playgroud)

如果您在[showInView]之前调用它,除了取消按钮之外的所有按钮都将被着色.希望这有助于某人!


Glo*_*ore 7

我创建了子类UICustomActionSheet,它允许在UIActionSheet中自定义字体,颜色和按钮图像.对于appstore来说绝对安全,你可以在下一个链接上找到这个类的代码:

https://github.com/gloomcore/UICustomActionSheet

好好享受!