How to change color of UIActionSheet in iOS 7?

六月ゝ 毕业季﹏ 提交于 2020-01-14 06:47:10

问题


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


回答1:


 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.




回答2:


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)




回答3:


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.



来源:https://stackoverflow.com/questions/19491197/how-to-change-color-of-uiactionsheet-in-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!