iOS-[NSAttributedString]設定富文字和計算富文字高度
阿新 • • 發佈:2018-12-23
/**
* 設定段落樣式
*
* @param lineSpacing 行高
* @param textcolor 字型顏色
* @param font 字型
*
* @return 富文字
*/
-(NSAttributedString *)stringWithParagraphlineSpeace:(CGFloat)lineSpacing
textColor:(UIColor *)textcolor
textFont:( UIFont *)font {
// 設定段落NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = lineSpacing;
// NSKernAttributeName字型間距NSDictionary *attributes = @{ NSParagraphStyleAttributeName:paragraphStyle,NSKernAttributeName:@1.5f};
NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:self attributes:attributes];
// 建立文字屬性NSDictionary * attriBute = @{NSForegroundColorAttributeName:textcolor,NSFontAttributeName:font};
[attriStr addAttributes:attriBute range:NSMakeRange(0, self.length)];
return attriStr;
}