背景
開發(fā)的過程中,我們會遇到諸如此類的需求(增加或者減小行間距的大谐荨)沃但。這時我們就糾結(jié)用UIVie w能否完成呢?答案是可以的淤刃。并且還是很簡單的逸贾。
奮斗的郅博
具體實現(xiàn)步驟
UITextView *textView = [[UITextView alloc] init];
NSString *upgradeDescription = @"你知道我在等你嗎铝侵?你肯定不知道吧!哈哈哈哈哈哈哈哈哈哈??";
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//行間距為9
paragraphStyle.lineSpacing = 9;
NSRange range = NSMakeRange(0, upgradeDescription.length);
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:upgradeDescription];
[attrStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
[attrStr addAttribute:NSForegroundColorAttributeName value: [UIColor RedColor] range:range];
[attrStr addAttribute:NSFontAttributeName value:updateTextFont range:range];
textView.attributedText = attrStr;
[self.view addSubview: textView];
結(jié)論:
正如上所述嗜诀,就是這么簡單主要就用NSMutableParagraphStyle的lineSpacing屬性就解決了這個問題了隆敢。