是否可以在iOS 7的tintColor
颜色中UIActionSheet
有按钮?我的意思是,如果我的应用程序是品牌tintColor
,例如红色,我不希望在操作表中使用蓝色按钮。UIAlertView
也是如此.
强调的是,这违反了Apple的规则,但这有效:
- (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];
}
}
}];
}
(符合UIActionSheetDelegate
)
尚未尝试UIAlertView。
这是可能的。以下是 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
在显示之前,请根据自己的喜好设置操作表的色调颜色。
在此实现中,我选择将破坏性按钮标题保留为红色,但可以更改。
请查看我的子类 UICustomAction Sheet。我刚刚推送了最新的更改,这些更改允许正确显示iOs6和iOs7设计的样式。https://github.com/gloomcore/UICustomActionSheet
您可以为每个按钮设置颜色,字体,文本颜色以及图像。适用于iPhone和iPad。组件对于应用商店来说是绝对安全的,因此您可以在应用程序中使用它。享受!