是否可以有UIActionSheet
iOS 7tintColor
颜色的按钮?我的意思是,如果我的应用程序是品牌tintColor
的,例如红色,我不想在操作表中出现蓝色按钮。与 相同UIAlertView
。
问问题
5223 次
3 回答
5
我想强调一下,这违反了 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。
于 2014-02-11T00:11:43.543 回答
1
有可能的。这是 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
在显示之前,将操作表的色调设置为您喜欢的颜色。
在这个实现中,我选择将破坏性按钮标题保持为红色,但这可以更改。
于 2013-10-24T20:56:28.803 回答
0
请看我的子类 UICustomActionSheet。我刚刚推送了最新的更改,它允许为 iOs6 和 iOs7 设计正确显示样式。 https://github.com/gloomcore/UICustomActionSheet
您可以为每个按钮设置颜色、字体、文本颜色以及图像。适用于 iPhone 和 iPad。组件对于 Appstore 来说是绝对安全的,因此您可以在您的应用程序中使用它。享受!
于 2014-02-12T22:28:16.827 回答