简体   繁体   English

在iOS8中自定义UIAlertController

[英]Customizing UIAlertController in iOS8

As in iOS8 UIAlertView is deprecated.we should use UIAlertController . 与在iOS8中一样, UIAlertView已被弃用。我们应该使用UIAlertController I want to customize it like font color, font family of message label of alertcontrller's view, also change background color of ok button.i don't know the right way to do that. 我想自定义它像字体颜色,alertcontrller视图的消息标签的字体系列,也改变ok按钮的背景颜色。我不知道正确的方法。

Please Help!! 请帮忙!!

Any help will be appreciable!! 任何帮助都会很明显!!

I think, you have been perform task with them. 我想,你一直在和他们一起执行任务。 But I think it's useful for someone. 但我认为这对某人有用。

Below code is working perfectly with my requirements. 下面的代码完全符合我的要求。 Please do changes according to your requirements. 请根据您的要求进行更改。

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *setCoverPhoto = [UIAlertAction
                                actionWithTitle:@"First Button"
                                style:UIAlertActionStyleDefault
                                handler:^(UIAlertAction *action){

                                    NSLog(@"First Button");

                                }];
[alertController addAction:setCoverPhoto];


UIAlertAction *deleteImageAct = [UIAlertAction
                                 actionWithTitle:@"Second Button"
                                 style:UIAlertActionStyleDefault
                                 handler:^(UIAlertAction *action) {

                                     NSLog(@"Second Button");

                                 }];
[alertController addAction:deleteImageAct];

UIAlertAction *setImageASNotif = [UIAlertAction
                                  actionWithTitle:@"Third Button"
                                  style:UIAlertActionStyleDefault
                                  handler:^(UIAlertAction *action) {

                                      NSLog(@"Third Button");

                                  }];
[alertController addAction:setImageASNotif];


alertController.view.tintColor = [UIColor whiteColor];

UIView *subView = alertController.view.subviews.firstObject;
UIView *alertContentView = subView.subviews.firstObject;
[alertContentView setBackgroundColor:[UIColor darkGrayColor]];

alertContentView.layer.cornerRadius = 5;

[self presentViewController:alertController animated:YES completion:nil];

Pretty darn good tutorial over at Matt Thompson's site: 在马特汤普森的网站上相当不错的教程:

http://nshipster.com/uialertcontroller/ http://nshipster.com/uialertcontroller/

Also, how to configure the alert on the iOS Developer Library: 另外,如何在iOS Developer Library上配置警报:

https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UIAlertController_class/index.html https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UIAlertController_class/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM