iOS 8之前貌似可以遍历UIAlertView的子视图来更改. 现在是gg了. 以下是傻瓜式教学.
步骤一: 使用KVC用一个Label替代需要显示的带字的view. 在这个Label里, 就可以自己随便设置字体颜色和大小. 下面的代码不用仔细看了 直接复制粘贴走不谢.
步骤二: 步骤一有一个问题是, 显示的UIAlertView上面的字没有内边距(字都顶到边上了,看起来特别山寨). 然而你想设置Label的内边距是没门的因为Label本来就没有内边距这个属性. 所以我们可以自定义一个带页边距的Label. 步骤一里的label继承这个label就自动有内边距了. 想要这个label的源码请戳这里http://www.jianshu.com/p/d8d29e30d2d4(感谢作者).
UIAlertView * alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
[alertView addButtonWithTitle:@"取消"];
[alertView addButtonWithTitle:@"去修改"];
SFLabel *textLabel = [[SFLabel alloc] init];
textLabel.font = [UIFont systemFontOfSize:13];
textLabel.textColor = [UIColor blackColor];
textLabel.backgroundColor = [UIColor clearColor];
textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;
textLabel.textAlignment = NSTextAlignmentCenter;
textLabel.text = @"你好我是豆芽爹, 以及树人groot的脑残粉";
[alertView setValue:textLabel forKey:@"accessoryView"];
[alertView show];
网友评论