- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib..
self.view.backgroundColor = [UIColor whiteColor];
UIButton *alertBtn = [UIButton buttonWithType:UIButtonTypeCustom];
alertBtn.backgroundColor = [UIColor redColor];
[alertBtn addTarget:self action:@selector(AlertBtnAtion) forControlEvents:UIControlEventTouchUpInside];
alertBtn.frame = CGRectMake(100, 100, 100, 100);
[self.view addSubview:alertBtn];
}
- (void)AlertBtnAtion
{
UIAlertController *AlertController = [UIAlertController alertControllerWithTitle:@"我有这么多的女朋友 今晚去谁家?" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *Action1 = [UIAlertAction actionWithTitle:@"去小兰家!" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[AlertController dismissViewControllerAnimated:YES completion:nil];
}];
[AlertController addAction:Action1];
UIAlertAction *Action2 = [UIAlertAction actionWithTitle:@"去小红家!" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[AlertController dismissViewControllerAnimated:YES completion:nil];
}];
[AlertController addAction:Action2];
UIAlertAction *Action3 = [UIAlertAction actionWithTitle:@"去小花家!" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[AlertController dismissViewControllerAnimated:YES completion:nil];
}];
[AlertController addAction:Action3];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Default" style:UIAlertActionStyleDefault handler:nil];
[defaultAction setValue:[UIColor blueColor] forKey:@"_titleTextColor"];
[AlertController addAction:defaultAction];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"都不见我,还是回家吧!"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction* action)
{
[AlertController dismissViewControllerAnimated: YES completion: nil];
}];
[AlertController addAction:cancel];
//修改title
NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"提示"];
[alertControllerStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
[alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)];
[AlertController setValue:alertControllerStr forKey:@"attributedTitle"];
//修改message
NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:@"提示内容"];
[alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 4)];
[alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 4)];
[AlertController setValue:alertControllerMessageStr forKey:@"attributedMessage"];
[self presentViewController:AlertController animated:YES completion:nil];
}
@end
UIAlertController的标题、内容的字体和颜色
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 在开发中,弹出框是必不可少的,通常情况下,我们只要弹出系统自带的弹出框就可以。but,在某些情况下,万恶的UI会要...
- 在开发中,弹出框是必不可少的,通常情况下,我们只要弹出系统自带的弹出框就可以。but,在某些情况下,万恶的U...
- 1.360开放平台:官网:http://dev.360.cn/[http://dev.360.cn/]上传APP到...