国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

iOS:個性化UITextView(縮進,行距,鋪滿)

2019-11-14 20:36:08
字體:
來源:轉載
供稿:網友

總體來說個性化定制UITextView中的內容有兩種方法:

1,從文件中讀取內容到UITextView,這個個人感覺使用rtfd和rtf格式文件效果非常好。

2,使用NSAttributeString進行定制

具體方法如下: 

  1. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];  
  2.     paragraphStyle.lineHeightMultiple = 20.f;  
  3.     paragraphStyle.maximumLineHeight = 25.f;  
  4.     paragraphStyle.minimumLineHeight = 15.f;  
  5.     paragraphStyle.firstLineHeadIndent = 20.f;  
  6. paragraphStyle.alignment = NSTextAlignmentJustified;  
  7.   
  8. NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:paragraphStyle, NSForegroundColorAttributeName:[UIColor colorWithRed:76./255. green:75./255. blue:71./255. alpha:1]  
  9.                                  };  
  10.  textView.attributedText = [[NSAttributedString alloc]initWithString:content attributes:attributes];  

 

當然也可以初始化一個NSMutableAttributedString,然后向里面添加文字樣式,最后將它賦給textView的AttributedText即可 

  1. NSMutableAttributedString *atr = [[NSMutableAttributedString alloc]initWithString:detail];  
  2.     [atr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, detail.length)];  
  3.     textView.attributedText = atr;  

 

另外,對于textview中的鏈接樣式,同樣也可以定制 

  1. NSDictionary *linkAttributes = @{NSForegroundColorAttributeName: [UIColor blueColor],  
  2.                                      NSUnderlineColorAttributeName: [UIColor blackColor],  
  3.                                      NSUnderlineStyleAttributeName: @(NSUnderlinePatternDash)};  
  4. self.linkTextAttributes = linkAttributes;  

 

這里只是個簡單的例子,具體還有很多屬性可以自行參考頭文件


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长葛市| 河北区| 黑龙江省| 利川市| 孟州市| 韶关市| 绥阳县| 嫩江县| 凤翔县| 宽城| 任丘市| 克山县| 商都县| 桓仁| 宁远县| 九台市| 梁河县| 中山市| 枞阳县| 岢岚县| 堆龙德庆县| 宁安市| 大新县| 东乌| 姚安县| 丰镇市| 辽源市| 稷山县| 曲阳县| 吴桥县| 石屏县| 甘孜县| 武宣县| 阳高县| 乌鲁木齐县| 南京市| 封丘县| 梁平县| 夏津县| 赤水市| 景德镇市|