UIActionSheet button's color
How can I change the color of UIActionSheet button's color?
iOS 8 (UIAlertController)
It's super simple to do if you're using a UIAlertController. Simply change the tint color on the view of the UIAlertController.
[alertController.view setTintColor:[UIColor red];
iOS 7 (UIActionSheet)
I successfully change the text color by using this simple method.
- (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];
}
}
}
Make sure to run this AFTER you call
[actionSheet showInView];
If you call it before [showInView], all buttons but the cancel button will be colored. Hope this helps someone!
I have created child class UICustomActionSheet, which allows customize fonts, colors and images of buttons inside UIActionSheet. It is absolutely safety for appstore, you can find code of this class on next link:
https://github.com/gloomcore/UICustomActionSheet
Enjoy it!
Unfortunately, without using undocumented API's, there is no official way to change the button's color on a UIActionSheet. You may be able to customize this if you subclass the UIActionSheet control.
See this example: http://blog.corywiles.com/customizing-uiactionsheet-buttons
We can use background images to do it. I think it is the easiest way.
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Actionsheet" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet addButtonWithTitle:@"Button 1"]; //Blue color
[actionSheet addButtonWithTitle:@"Button 2"];
[actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet addButtonWithTitle:nil];
[actionSheet setCancelButtonIndex:2];
[actionSheet setDestructiveButtonIndex:1];
[actionSheet showInView:self.view];
UIButton *button = [[actionSheet subviews] objectAtIndex:1];
UIImage *img = [button backgroundImageForState:UIControlStateHighlighted];//[UIImage imageNamed:@"alert_button.png"];
[button setBackgroundImage:img forState:UIControlStateNormal];