iOS:个性化UITextView(缩进,行距,铺满)
来源:互联网 发布:com.cn域名怎么样 编辑:程序博客网 时间:2024/06/18 16:27
总体来说个性化定制UITextView中的内容有两种方法:
1,从文件中读取内容到UITextView,这个个人感觉使用rtfd和rtf格式文件效果非常好。
2,使用NSAttributeString进行定制
具体方法如下:
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
- paragraphStyle.lineHeightMultiple = 20.f;
- paragraphStyle.maximumLineHeight = 25.f;
- paragraphStyle.minimumLineHeight = 15.f;
- paragraphStyle.firstLineHeadIndent = 20.f;
- paragraphStyle.alignment = NSTextAlignmentJustified;
- NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:paragraphStyle, NSForegroundColorAttributeName:[UIColor colorWithRed:76./255. green:75./255. blue:71./255. alpha:1]
- };
- textView.attributedText = [[NSAttributedString alloc]initWithString:content attributes:attributes];
当然也可以初始化一个NSMutableAttributedString,然后向里面添加文字样式,最后将它赋给textView的AttributedText即可
- NSMutableAttributedString *atr = [[NSMutableAttributedString alloc]initWithString:detail];
- [atr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, detail.length)];
- textView.attributedText = atr;
另外,对于textview中的链接样式,同样也可以定制
- NSDictionary *linkAttributes = @{NSForegroundColorAttributeName: [UIColor blueColor],
- NSUnderlineColorAttributeName: [UIColor blackColor],
- NSUnderlineStyleAttributeName: @(NSUnderlinePatternDash)};
- self.linkTextAttributes = linkAttributes;
0 0
- iOS:个性化UITextView(缩进,行距,铺满)
- iOS:个性化UITextView(缩进,行距,铺满)
- iOS:个性化UITextView(缩进,行距,铺满)
- iOS:个性化UITextView(缩进,行距,铺满)
- ios UITextView设置行距
- IOS UITextView 首行缩进
- 【iOS开发系列】个性化UITextView
- IOS Label行距间隔 首行缩进的解决
- IOS Label行距间隔 首行缩进的解决 原创
- iOS给UILabel设置缩进、行距、字体颜色
- css设置段落缩进、行距
- label 设置行距 首行缩进
- iOS UITextView 首行缩进 撤销输入 反撤销输入的实现
- ios UITextView
- IOS UITextView
- iOS UITextView
- iOS UITextView
- iOS:设置UILabel行距实例
- Python学习(一)
- IT从业人员的经历
- hadoop 2.2.0 集群部署 (经过亲自测试通过并且步骤非常详细)
- GPS北斗双模技术应用开发研究—应用数据交互
- ehcache使用
- iOS:个性化UITextView(缩进,行距,铺满)
- Hadoop HA介绍
- 排序算法比较
- ssh-keygen 的 详解
- iOS 关于presentViewController弹出页面反应迟钝的问题
- Using multiple UIWindows in iOS applications
- H.264帧间预测以及P帧
- Java学习笔记2——foreach和方法重载
- 1.Hibernate单向有链接表映射