更改UIActionSheet中项目的文本颜色 - iOS 8 [英] Change Text Color of Items in UIActionSheet - iOS 8

查看:94
本文介绍了更改UIActionSheet中项目的文本颜色 - iOS 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用以下代码来更改我在 UIActionSheet 中添加的项目的文字颜色。:

I had been using following code to change text color of items which I add in UIActionSheet.:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
    for (UIView *subview in actionSheet.subviews) {
        if ([subview isKindOfClass:[UIButton class]]) {
            UIButton *button = (UIButton *)subview;
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
    }
}

它在<$中工作正常c $ c> iOS7 ,但在 iOS8 中,上述代码不会更改项目的文字颜色。

It works fine in iOS7, but in iOS8 the above code doesn't change the text color of items.

现在我的问题是如何使用 iOS8 UIActionSheet 中添加的项目的文本颜色C> ??



其他信息:

我添加断点以查看上述代码中的以下行是否被执行:

Now my question is how to change the text color of items which I add in UIActionSheet using iOS8??

Additional Info:
I added breakpoint to see whether following lines from the above code get executed or not:

UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

这些行不会被执行。所以, if([subview isKindOfClass:[UIButton class]])对于<$ c的所有项目总是 false $ C> actionSheet.subviews 。所以我认为
UIActionSheet 的视图heirarchy已被更改。

These lines do not get executed. So, if([subview isKindOfClass:[UIButton class]]) is always false for all items of actionSheet.subviews. So what I think is that the view heirarchy of UIActionSheet has been changed.

推荐答案

如果您仍想使用 UIActionSheet 而不是 UIAlertController ,这是一种简单的方法支持较旧的iOS版本。

There's an easy way if you still want to use UIActionSheet instead of UIAlertController in order to support older iOS versions.

UIActionSheet 实际使用 UIAlertController 在iOS 8中,它有一个私有属性 _alertController

UIActionSheet actually uses UIAlertController in iOS 8, and it has a private property _alertController.

SEL selector = NSSelectorFromString(@"_alertController");
if ([actionSheet respondsToSelector:selector])
{
    UIAlertController *alertController = [actionSheet valueForKey:@"_alertController"];
    if ([alertController isKindOfClass:[UIAlertController class]])
    {
        alertController.view.tintColor = [UIColor blueColor];
    }
}
else
{
    // use other methods for iOS 7 or older.
}

这篇关于更改UIActionSheet中项目的文本颜色 - iOS 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆