问题
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