Reputation: 29326
I use green as the "action color" throughout my app, and I want the options in my UIActionSheets to be green as well, for consistency. How can I change the colour of the UIActionSheet options to green from blue?
Upvotes: 10
Views: 9063
Reputation: 1120
You can change easily the application's tint color using this short function on your AppDelegate didFinishLaunchingWithOptions method.
[[UIView appearance] setTintColor:[UIColor redColor]];
Hope it will help you :)
Upvotes: 0
Reputation: 1297
You could do something like this:
// 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];
}
}
If you're going to reuse this a lot, I'd subclass UIActionSheet and use this code.
Upvotes: 18
Reputation: 3785
Utilize the willPresentActionSheet
delegate method of UIActionSheet
to change the action sheet button color.
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
button.titleLabel.textColor = [UIColor greenColor];
}
}
}
Upvotes: 28