Bcf*_*Ant 31 objective-c ios uialertcontroller ios9
我使用以下代码来呈现UIAlertController操作表,其中项目文本为红色.我已经使用了tint属性来设置颜色.
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
alertController.view.tintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
高亮或选择时,文本颜色似乎默认为蓝色.这是正常的,我该怎么做呢?
Fre*_*orf 48
这是一个已知的Bug,请参阅https://openradar.appspot.com/22209332
要修复它,请在"完成"处理程序中重新应用色调颜色.这是我的Swift解决方案,您将能够轻松地为ObjC进行调整:
alertController.view.tintColor = UIColor.redColor() // apply 1st time to prevent flicker from Blue to Red when displaying
navigationController?.presentViewController(alertController, animated: true, completion: {
// Bugfix: iOS9 - Tint not fully Applied without Reapplying
alertController.view.tintColor = UIColor.redColor()
})
Run Code Online (Sandbox Code Playgroud)
注意:这并不能完全修复Bug.在设备旋转时,您会注意到按钮按系统默认(=蓝色)色调重新着色.
预计它将通过iOS 9.1修复.
编辑2015年10月23日:iOS 9.1仍未修复.几天前发布的iOS 9.1 + Xcode 7.1(7B91B)重新测试.截至目前设置.tintColor不起作用,但是如您所述,您可以设置整个Application的tintColor,例如在AppDelegate中设置didFinishLaunchingWithOptions window?.tintColor = UIColor.redColor().这也会使AlertController按钮着色,但在某些情况下可能不适合,因为此色调适用于整个应用程序.
Edd*_*ddy 38
只需在presentViewController之后添加tintColor即可.适用于iOS 9.0.2
[self presentViewController:alertController animated:YES completion:nil];
[alertController.view setTintColor:[UIColor yellowColor]];
Run Code Online (Sandbox Code Playgroud)
小智 13
您还可以在appdelegate中更改应用色调颜色.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.tintcolor = [UIColor yellowColor];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
适合我.
更新Swift 4,Xcode 9
private static func setupAppearanceForAlertController() {
let view = UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self])
view.tintColor = .black
}
Run Code Online (Sandbox Code Playgroud)
您可以像这样更改按钮颜色
UIAlertAction* button = [UIAlertAction
actionWithTitle:@"Delete Profile"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//Add Action.
}];
[button setValue:[UIColor redColor] forKey:@"titleTextColor"];
Run Code Online (Sandbox Code Playgroud)
通过使用这一行 [button setValue:[UIColor redColor] forKey:@"titleTextColor"]; 您可以更改操作表的按钮颜色
我仍然很困惑你想要实现什么。但你可以尝试苹果的创建按钮的方式Destructive(默认文本颜色为红色)。
您创建的代码UIAlertAction不使用Default您想要的红色按钮的样式。而是使用UIAlertActionStyleDestructive. 示例代码:
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:YES completion:nil];
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17403 次 |
| 最近记录: |