iOS UIAlertController alert中内容居左显示的小技巧

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"本次升级说明" message:info preferredStyle:(UIAlertControllerStyleAlert)];
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.alignment = NSTextAlignmentLeft;
NSMutableAttributedString *atrStr = [[NSMutableAttributedString alloc] initWithString:info attributes:@{NSParagraphStyleAttributeName:paraStyle,NSFontAttributeName:[UIFont systemFontOfSize:13.0]}];

[alert setValue:atrStr forKey:@"attributedMessage"];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
   //
}];
[alert addAction:action];
[self presentViewController:alert animated:YES completion:nil];
左对齐demo.png

你可能感兴趣的:(iOS UIAlertController alert中内容居左显示的小技巧)