更改UIAlertview和UIActionsheet按钮的色调颜色

Bob*_*sky 8 cocoa-touch objective-c uialertview uiactionsheet ios

我正在尝试为iOS 7调整我的应用程序.我遇到的问题是我无法更改某些控件的色调颜色.

我添加了

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if (IOS7_OR_LATER)
    self.window.tintColor = [self greenTintColor];
Run Code Online (Sandbox Code Playgroud)

到我的应用代表的

           - (BOOL)application:(UIApplication *)application
 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Run Code Online (Sandbox Code Playgroud)

它主要有所帮助,但消息框和操作表按钮的颜色仍然是默认的蓝色.

我怎样才能重新着色所有这些按钮呢?

一些截图:

iOS7留言框 iOS7操作表

Tos*_*lji 11

由于UIAlertView已被弃用,您可以.使用UIAlertController.

你可以使用tintColor财产.

UIAlertView类旨在按原样使用,不支持子类化.此类的视图层次结构是私有的,不得修改.

- 来自Apple Doc

您可以使用tintColor属性或您可以使用某些自定义库,您可以在cocoacontrols.com找到它.

  • 在iOS 8中有alert.view.tintColor = UIColor.redColor() (5认同)

小智 11

我能够在app delegate中将取消按钮的文本颜色更改为白色.

[[UIView appearance] setTintColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)

  • 嗯,它做得比它应该做的更多.我宁愿使用`[[UIView appearanceWhenContainedIn:[UIAlertView class],nil] setTintColor:[UIColor whiteColor]];`和`[[UIView appearanceWhenContainedIn:[UIAlertController class],nil] setTintColor:[UIColor whiteColor]];` (6认同)

小智 6

对于Actionsheet您可以使用

利用UIActionSheet 的willPresentActionSheet委托方法更改操作表按钮颜色.

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
    for (UIView *subview in actionSheet.subviews) {
        if ([subview isKindOfClass:[UIButton class]]) {
            UIButton *button = (UIButton *)subview;
            button.titleLabel.textColor = [UIColor greenColor];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)