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
.
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.
It is possible. Here is a quick implementation for iOS7:
@interface LNActionSheet : UIActionSheet
{
NSString* _destructiveButtonTitle;
UIColor* _customtintColor;
}
@end
@implementation LNActionSheet
- (id)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...
{
self = [super initWithTitle:title delegate:delegate cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle otherButtonTitles:nil];
if(self)
{
va_list list;
va_start(list, otherButtonTitles);
for(NSString* title = otherButtonTitles; title != nil; title = va_arg(list, NSString*))
{
[self addButtonWithTitle:title];
}
va_end(list);
_destructiveButtonTitle = destructiveButtonTitle;
}
return self;
}
- (void)setTintColor:(UIColor *)tintColor
{
_customtintColor = tintColor;
}
-(void)tintColorDidChange
{
[super tintColorDidChange];
for(id subview in self.subviews)
{
if([subview isKindOfClass:[UIButton class]])
{
UIButton* button = subview;
if(![button.titleLabel.text isEqualToString:_destructiveButtonTitle])
{
[button setTitleColor:_customtintColor forState:UIControlStateNormal];
}
}
}
}
@end
Before showing, set the tint color of the action sheet to your liking.
In this implementation, I have elected to keep the destructive button title as red, but this can be changed.
Please look at my child class UICustomActionSheet. I've just pushed the latest changes, which allow to display styling correctly for iOs6 and iOs7 design. https://github.com/gloomcore/UICustomActionSheet
You can set the colors, fonts, text colors and also images for each buttons. Works fine both for iPhone and iPad. Component is absolutely safety for Appstore so you can use it in your applications. Enjoy!
© 2022 - 2024 — McMap. All rights reserved.