首先,我变动的是系统的UIAlertController,而UIAlertView也有对应的方法能改变样式,这里就不列举了。
方法比较简单,就不深入介绍了,主要运用的是KVC方法。
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelButton = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *confirmButton = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[cancelButton setValue:k333333Color forKey:@"titleTextColor"];
[alertController addAction:cancelButton];
[alertController addAction:confirmButton];
[self presentViewController:alertController animated:YES completion:nil];
就可以设置对应的按钮颜色。
值得一提的是,这个alertController只允许设置一个样式为cancel的按钮,会自动排布在最左边。当你设置多于1个的时候,会报错。这一点千万记得。

本文介绍如何使用KVC方法自定义UIAlertController的样式,包括按钮颜色的设置。通过示例代码展示了如何创建UIAlertController并添加不同样式的按钮,同时提醒开发者关于按钮样式的限制。
1438

被折叠的 条评论
为什么被折叠?



