UIActionSheet button's color

后端 未结 5 999
失恋的感觉
失恋的感觉 2020-11-29 06:27

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

5条回答
  •  天命终不由人
    2020-11-29 06:39

    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!

提交回复
热议问题