Narendra Mistri
Narendra Mistri

Reputation: 113

How to change color of UIActionSheet in iOS 7?

I wish I could use custom colors to display Actionsheet in iOS 7.I've been searching for proper answer since couple of days. Any help will be appreciated Thanks..

I'm using UIActionsheet to display PickerView in it

Upvotes: 0

Views: 5625

Answers (3)

Adam Waite
Adam Waite

Reputation: 18855

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)

Upvotes: 3

Gloomcore
Gloomcore

Reputation: 950

I have created class which extedns UIActionSheet funcionality with ability to set colors, fonts, text colors and images to Action Sheet buttons. It works fine both for iOs6 and iOs7, and both for iPhone and iPad applications. https://github.com/gloomcore/UICustomActionSheet It doesn't use hidden API, so it's safety for Appstore. Enjoy.

Upvotes: 1

Toseef Khilji
Toseef Khilji

Reputation: 17409

 UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy.
 If you need to present a sheet with more customization than provided by the
 UIActionSheet API, you can create your own.

As per apple doc Reference,

So you have to use some custom class for that,

show this cocoacontrols.

Upvotes: 3

Related Questions