iOS之改变UIAlertViewController字体的颜色
2017-05-17 16:39
447 查看
NSString *message = @"请确认信息是否正确?"; NSString *title = @"提示"; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet]; //改变title的大小和颜色 NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:title]; [titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0, title.length)]; [titleAtt addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, title.length)]; [alertController setValue:titleAtt forKey:@"attributedTitle"]; //改变message的大小和颜色 NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:message]; [messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0, message.length)]; [messageAtt addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, message.length)]; [alertController setValue:messageAtt forKey:@"attributedMessage"]; [self presentViewController:alertController animated:YES completion:nil];
上面的是修改UIAlertViewController的title和message字体的大小和颜色,采用的是修改attributedString其中的NSForegroundColorAttributeName颜色属性和NSFontAttributeName字体大小属性。UIAlertViewController中的标题的key:@"attributedTitle",标题中提示信息的key:@"attributedMessage"。
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:nil]; [alertAction setValue:[UIColor purpleColor] forKey:@"_titleTextColor"]; // alertController.view.tintColor = [UIColor greenColor]; [alertController addAction:alertAction]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; /*取消按钮的颜色*/ [cancel setValue:[UIColor redColor] forKey:@"_titleTextColor"]; [alertController addAction:cancel];
修改UIAlertViewController中修改所有按钮的颜色使用下面这个方法:
alertController.view.tintColor = [UIColor greenColor];
修改单个UIAlertAction按钮的字体颜色使用下面这个方法:
[cancel setValue:[UIColor redColor] forKey:@"_titleTextColor"];
相关文章推荐
- ios:改变tableview的titleForHeaderInSection字体颜色设置
- iOS 在viewController中改变状态栏颜色
- UI基础_UIAlertController/UIAlertView使用和字体大小颜色
- 改变UIALertView中button的字体颜色
- 用runtime自定义UIAlertViewController的字体大小和颜色
- iOS中通过设置CSS改变WebView字体大小,颜色,背景颜色
- iOS中通过设置CSS改变WebView字体大小,颜色,背景颜色
- UIAlertViewController 基本使用+自定义(字体颜色,大小,对齐方式)
- iOS中通过设置CSS改变WebView字体大小,颜色,背景颜色
- iOS中通过设置CSS改变WebView字体大小,颜色,背景颜色
- iOS开发用Tableview实现能改变字体颜色的高仿系统的ActionSheet
- ios UIButton来回点击切换改变字体颜色
- Android textview 同时改变字符串中部分字体的颜色与大小
- Xamarin.IOS UIAlertController 自定义字体
- iOS UILabel改变指定字体大小和颜色
- ios iOS中改变部分字体颜色
- iOS-UITabBar的使用包括选中前后使用不同的自定义颜色以及图标颜色的改变问题)imageView,titles
- iOS 临时想改变状态栏字体颜色
- Android textview 同时改变字符串中部分字体的颜色与大小
- iOS滑动tableView来改变导航栏的颜色