- (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到...