本文介绍了在UIActionSheet按钮中更改文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目中,我使用 UIActionSheet
来显示某些排序类型。我想更改操作表按钮中显示的文本的颜色。我们如何更改文本颜色?
In my project, I am using UIActionSheet
for displaying for some sorting type. I want to change the color of the text displayed in the action sheet buttons. How can we change the text color?
推荐答案
iOS 8: UIActionSheet
已弃用。 UIAlertController
尊重 - [UIView tintColor]
,所以这样做:
iOS 8: UIActionSheet
is deprecated. UIAlertController
respects -[UIView tintColor]
, so this works:
alertController.view.tintColor = [UIColor redColor];
更好的是,在应用程序委托中设置整个窗口的色调颜色:
Better yet, set the whole window's tint color in your application delegate:
self.window.tintColor = [UIColor redColor];
iOS 7:在您的操作表委托中,实施 -willPresentActionSheet:
如下:
iOS 7: In your action sheet delegate, implement -willPresentActionSheet:
as follows:
- (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];
}
}
}
这篇关于在UIActionSheet按钮中更改文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!