kir*_*iri 33 uiactionsheet ios
在我的项目中,我UIActionSheet用于显示某些排序类型.我想更改操作表按钮中显示的文本的颜色.我们怎样才能改变文字颜色?
jrc*_*jrc 73
iOS 8: UIActionSheet已弃用.UIAlertController尊重-[UIView tintColor],所以这是有效的:
alertController.view.tintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
更好的是,在应用程序委托中设置整个窗口的色调颜色:
self.window.tintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
iOS 7:在您的操作表委托中,实现-willPresentActionSheet:如下:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
}
}
Run Code Online (Sandbox Code Playgroud)
lif*_*joy 19
在iOS 8中,这一切都不再适用.UIActionSheet文本似乎从window.tintColor获取其颜色.
bla*_*011 17
这适用于iOS8
[[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)
小智 12
如果您想浏览UIActionSheet子视图,则不应直接设置文本颜色,UILabel而应使用该UIButton setTitleColor:forState方法.否则,初始颜色将在UIControlEventTouchDragOutside等事件上重新设置.
这是正确的方法,重用jrc的代码:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
}
}
Run Code Online (Sandbox Code Playgroud)
可能是一个较晚的答案,但我认为它可以帮助某人。
iOS 8: 您可以简单地使用以下样式初始化UIAlertAction:UIAlertActionStyleDestructive,如下所示:
UIAlertAction *delete = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action){
// your code in here
}];
Run Code Online (Sandbox Code Playgroud)
默认情况下,这会使按钮的文本变为红色。
小智 6
要更改警报操作中的特定按钮颜色,请使用此
let cancelAction = UIAlertAction(title: "Success", style: .cancel, handler: nil)
cancelAction.setValue(UIColor.green, forKey: "titleTextColor")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38873 次 |
| 最近记录: |