封装好的可设置标题、正文字体的默认样式UIAlertController
来源:互联网 发布:软件验收测试 编辑:程序博客网 时间:2024/05/21 22:41
iOS8之后,主要使用UIAlertController进行信息的显示,而默认的样式使用的比较多,所以封装了一个,以方便以后使用。
调用以下函数即可:
-(void)showIntroDuction:(NSString *)title :(NSString *)showText :(NSString *)btnStr :(UIFont *)titleFont :(UIFont *) showTextFont :(UIColor *) titleColor :(UIColor *)showTextColor :(UIColor *)btnColor{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:showText preferredStyle:UIAlertControllerStyleAlert]; // 设置标题的字体 NSMutableAttributedString *attributedStrTitle = [[NSMutableAttributedString alloc]initWithString:title]; [attributedStrTitle addAttribute:NSFontAttributeName value:titleFont range:NSMakeRange(0, [title length])]; [attributedStrTitle addAttribute:NSForegroundColorAttributeName value:titleColor range:NSMakeRange(0, [title length])]; // 利用KVC赋值 [alertController setValue:attributedStrTitle forKey:@"attributedTitle"]; // 设置正文的字体 NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:showText]; [messageAtt addAttribute:NSFontAttributeName value:showTextFont range:NSMakeRange(0, [showText length])]; [messageAtt addAttribute:NSForegroundColorAttributeName value:showTextColor range:NSMakeRange(0, [showText length])]; [alertController setValue:messageAtt forKey:@"attributedMessage"]; // 按钮 UIAlertAction *alertAction = [UIAlertAction actionWithTitle:btnStr style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:alertAction]; // 按钮颜色 [alertAction setValue:btnColor forKey:@"_titleTextColor"]; [self presentViewController:alertController animated:YES completion:nil];}
阅读全文
0 0
- 封装好的可设置标题、正文字体的默认样式UIAlertController
- axure中默认字体样式的设置
- word设置正文默认字体
- 改变UIAlertController的标题、内容的字体和颜色
- 改变UIAlertController的标题、内容的字体和颜色
- 改变UIAlertController的标题、内容的字体和颜色
- 字体样式的设置
- Android 自定义字体样式 及系统默认字体样式 的设置
- 封装好的友盟分享--默认的样式与自定义的样式
- phpstrom 字体样式的设置
- 设置emacs的默认字体
- Word2010中如何设置多级编号 把默认标题的样式设置为带有多级编号
- TabHost 改变默认样式的高度,字体
- UIAlertController 两个按钮的样式
- UIAlertController 两个按钮的样式
- 基于UIAlertController的封装调用
- UIAlertController的封装,方便使用
- UIAlertView和UIAlertController的封装
- Switf: 消除警告-treating unicode character whitespace
- Ubuntu 12.04用root登录
- MYSQL主从热备配置
- linux 信号简介
- java线程安全之——自旋锁
- 封装好的可设置标题、正文字体的默认样式UIAlertController
- 夜间切换模式
- TensorFlow 保存和导入计算图中的部分节点
- @Controller和@RestController的区别?
- grep排除搜索的目录
- Java--interrupt(),interrupted(),isInterrupted()
- Laravel 读取 config 下的数据
- PullLayout下拉得动态头布局
- workerman启动失败