iosuiactionsheet

Change text color in UIActionSheet buttons


In my project, I am using UIActionSheet for displaying for some sorting type. I want to change the color of the text displayed in the action sheet buttons. How can we change the text color?


Solution

  • iOS 8: UIActionSheet is deprecated. UIAlertController respects -[UIView tintColor], so this works:

    alertController.view.tintColor = [UIColor redColor];
    

    Better yet, set the whole window's tint color in your application delegate:

    self.window.tintColor = [UIColor redColor];
    

    iOS 7: In your action sheet delegate, implement -willPresentActionSheet: as follows:

    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet
    {
        for (UIView *subview in actionSheet.subviews) {
            if ([subview isKindOfClass:[UIButton class]]) {
                UIButton *button = (UIButton *)subview;
                [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
            }
        }
    }