阅读背景:

ios - 可以改变系统弹框字体大小以及颜色的方法

来源:互联网 
  • 代码
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    
    UIAlertController * alertVc = [UIAlertController alertControllerWithTitle:@"立即锁" message:@"设定后车辆被立即锁定" preferredStyle:UIAlertControllerStyleAlert];
    NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"立即锁"];
//设置标题颜色
    [alertControllerStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 3)];
    [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 3)];
//通过kvc赋值
    [alertVc setValue:alertControllerStr forKey:@"attributedTitle"];
//设置标题中的message颜色
    NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:@"设定后车辆被立即锁定"];
    [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 10)];
    [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 10)];
//通过kvc赋值
    [alertVc setValue:alertControllerMessageStr forKey:@"attributedMessage"];
    UIAlertAction * actConfirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction * actCan = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];
//设置按钮颜色
    [actCan setValue:[UIColor blackColor] forKey:@"titleTextColor"];
    [alertVc addAction:actCan];
    [alertVc addAction:actConfirm];
    [self presentViewController:alertVc animated:YES completion:^{
    }];
}-(void)touchesBegan:(NSSet<UITouch 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: