在iOS 8中,似乎按钮UIAlertController
(特别是操作表类型)以及按钮UIActivityViewController
的颜色都从主窗口的tintColor中获取。
如何更改按钮文字的颜色?我已经尝试过使用外观代理,例如:
[[UIButton appearanceWhenContainedIn:[UIActivityViewController class], nil] setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
但这没有效果。我的窗口的tintColor是白色的,因此UIActivityViewController按钮上的文本也是白色的,因此无法看到。更改窗口的tintColor可以解决此问题,但是会弄乱应用程序的其余部分。
请参阅我的屏幕截图,UIActivityViewController
底部带有白色文本的白色取消按钮:
同样的情况也适用于UIActionSheet(是的,我知道它已被弃用)和具有ActionSheet类型的UIAlertController。
如何在不更改整个应用程序的tintColor的情况下使这些窗口上的文本可读?提前致谢!
除了为您的应用程序定义的全局色调颜色之外,每个视图控制器还允许您覆盖该控制器的色调颜色。在这种情况下,最好的选择是在初始化之后但在演示之前在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];
如果您在应用程序中经常执行此操作,则可以使用子类或类别来避免代码重复。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句