10

我在整个应用程序中使用绿色作为“动作颜色”,并且我希望 UIActionSheets 中的选项也为绿色,以保持一致性。如何将 UIActionSheet 选项的颜色从蓝色更改为绿色?

4

3 回答 3

28

利用willPresentActionSheet委托方法UIActionSheet更改操作表按钮颜色。

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
    for (UIView *subview in actionSheet.subviews) {
        if ([subview isKindOfClass:[UIButton class]]) {
            UIButton *button = (UIButton *)subview;
            button.titleLabel.textColor = [UIColor greenColor];
        }
    }
}
于 2013-10-06T20:56:57.213 回答
18

你可以这样做:

// Your code to instantiate the UIActionSheet
UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
// Configure actionSheet

// Iterate through the sub views of the action sheet
for (id actionSheetSubview in actionSheet.subviews) {
    // Change the font color if the sub view is a UIButton
    if ([actionSheetSubview isKindOfClass:[UIButton class]]) {
        UIButton *button = (UIButton *)actionSheetSubview;
        [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor greenColor] forState:UIControlStateSelected];
        [button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];

    }
}

如果你要重用这个很多,我会继承 UIActionSheet 并使用这个代码。

于 2013-10-06T18:39:37.223 回答
0

您可以使用 AppDelegate didFinishLaunchingWithOptions 方法上的这个简短函数轻松更改应用程序的色调颜色。

[[UIView appearance] setTintColor:[UIColor redColor]];

希望它会帮助你:)

于 2015-12-02T13:43:30.843 回答