Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tintColor of UIActionSheet (or UIAlertView) (iOS 7+)

Is it possible to have buttons in UIActionSheet in iOS 7's tintColor color? I mean if my app is in brand tintColor, for example red, I don't want blue buttons in action sheet. The same with UIAlertView.

like image 647
user500 Avatar asked Oct 24 '13 19:10

user500


1 Answers

I want to stress that this violates Apple's rules, but this works:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
    [actionSheet.subviews enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) {
        if ([subview isKindOfClass:[UIButton class]]) {
            UIButton *button = (UIButton *)subview;
            button.titleLabel.textColor = [UIColor greenColor];
            NSString *buttonText = button.titleLabel.text;
            if ([buttonText isEqualToString:NSLocalizedString(@"Cancel", nil)]) {
               [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
            }
        }
    }];
}

(conform to UIActionSheetDelegate)

Not tried UIAlertView yet.

like image 136
Adam Waite Avatar answered Oct 04 '22 16:10

Adam Waite