Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActionSheet button's color

How can I change the color of UIActionSheet button's color?

like image 904
Abhinav Avatar asked Nov 22 '10 17:11

Abhinav


3 Answers

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!

like image 104
Rymnel Avatar answered Nov 18 '22 16:11

Rymnel


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!

like image 7
Gloomcore Avatar answered Nov 18 '22 14:11

Gloomcore


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

like image 1
Evan Mulawski Avatar answered Nov 18 '22 16:11

Evan Mulawski