官方公开的属性,并不多,貌似可以定制的东西很有限,但是,我们不能忽略的是UIAlertController是继承与UIViewController的,我们很容易联想到UIViewController的一些特征和属性,最简单的一点就是UIViewController有一个View,我们可以给View加东西。 既然如此,那就去加东西。
实例代码如下
-
(void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
button.backgroundColor = [UIColor yellowColor];
[button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
} -
(void)buttonClick
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"没有标题的标题"
message:@"学无止境,漫漫长路"
preferredStyle:UIAlertControllerStyleAlert ];//添加取消到UIAlertController中
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:cancelAction];//添加确定到UIAlertController中
UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:OKAction];UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 30, 30)];
imageView2.image = [UIImage imageNamed:@"WechatIMG20"];
[alertController.view addSubview:imageView2];[self presentViewController:alertController animated:YES completion:nil];
}
对你有帮助的话,点个赞吧👍
网友评论