UIAlertController 修改 title 或 message 样式相关

UIAlertController 文字换行后默认对齐方式为居中,若想调整其相关样式属性可以借鉴如下方式进行修改,具体实现方式 code 如下:

NSString *msg = @"1、注销≠退出登录;\n注销:对不再使用的账号进行清空移除;注销后,App中数据将全部丢失,不可再找回;\n2、注销后,与账号相关的数据都会删除,如购买的商品、购买记录等,请慎重操作;\n3、【退出登录】是在【我的】首页中最下方处~";
UIAlertController *alterCon = [UIAlertController alertControllerWithTitle:@"注销须知!" message:msg preferredStyle:UIAlertControllerStyleAlert];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = NSTextAlignmentLeft; // 对齐方式
paragraphStyle.lineSpacing = 5.0; // 行间距
NSDictionary *attributes = @{NSFontAttributeName : [UIFont systemFontOfSize:18.0], NSParagraphStyleAttributeName : paragraphStyle}; // 属性样式 NSForegroundColorAttributeName、NSFontAttributeName 等等
NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc] initWithString:msg];
[attributedTitle addAttributes:attributes range:NSMakeRange(0, msg.length)];
//[alterCon setValue:attributedTitle forKey:@"attributedTitle"]; // 标题:attributedTitle
[alterCon setValue:attributedTitle forKey:@"attributedMessage"]; // 内容:attributedMessage
UIAlertAction *actionTrue = [UIAlertAction actionWithTitle:@"确认,继续注销" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
      // do somethings
}];
// UIAlertAction 也同样可以通过类似 [action setValue:[UIColor blueColor] forKey:@"titleTextColor"]; 的方式进行修改
UIAlertAction *actionFalse = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alterCon addAction:actionTrue];
[alterCon addAction:actionFalse];
[self presentViewController:alterCon animated:YES completion:nil];


以上便是此次分享的全部内容,希望能对大家有所帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值