Dis*_*Dev 31 objective-c tintcolor ios ios8
在iOS 8中,似乎按钮UIAlertController
(特别是动作表类型)以及UIActivityViewController
从主窗口的tintColor获取颜色的按钮.
如何更改按钮文本的颜色?我试过使用这样的外观代理:
[[UIButton appearanceWhenContainedIn:[UIActivityViewController class], nil] setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
但它没有效果.我的窗口的tintColor是白色的,因此UIActivityViewController按钮上的文本也是白色的,无法看到.更改我的窗口的tintColor解决了这个问题,但它弄乱了应用程序的其余部分.
UIActivityViewController
通过底部带有白色文本的白色取消按钮查看我的屏幕截图:
同样的事情适用于UIActionSheet(是的,我知道它已被弃用)和带有actionSheet类型的UIAlertController.
如何在不更改整个应用程序的tintColor的情况下使这些窗口上的文本可读?提前致谢!
小智 30
除了为应用程序定义的全局色调颜色外,每个视图控制器还允许您覆盖该控制器的色调颜色.在这种情况下,最好的办法是在初始化之后但在呈现之前在UIActivityViewController上设置tintColor.
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:activities];
//Set the tint color on just the activity controller as needed here before presenting
[activityController.view setTintColor:[UIColor blueColor]];
[self presentViewController:activityController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
如果您在应用程序中执行此操作,则可以使用子类或类别来避免代码重复.
小智 21
这对我来说很有用UIAlertController
.
[[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor blackColor]];
Run Code Online (Sandbox Code Playgroud)