message默认显示是居中,现在需要修改为左对齐样式:
利用runtime获取UIAlertController的属性:
unsigned int count = 0;
Ivar *property = class_copyIvarList([UIAlertController class], &count);
for (int i = 0; i < count; i++) {
Ivar var = property[i];
const char *name = ivar_getName(var);
const char *type = ivar_getTypeEncoding(var);
NSLog(@"%s ====== %s",name,type);
}
可以设置message富文本(左对齐、字体、颜色):
NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:message];
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.alignment = NSTextAlignmentLeft;
[alertControllerMessageStr setAttributes:@{NSParagraphStyleAttributeName:paragraph} range:NSMakeRange(0, alertControllerMessageStr.length)];
利用runtime获取到属性:attributedMessage。使用KVO修改message文字样式对齐方式:
[alertContro setValue:alertControllerMessageStr forKey:@"attributedMessage"]
效果图
网友评论