在项目中需要文本实现word中悬挂缩进样式时,可以仿照下面的方式来做:
- (NSAttributedString *)getAttributeStringWith:(NSString *)str {
NSDictionary *attributes = @{NSFontAttributeName:FONT_SIZE(12),
NSForegroundColorAttributeName:UIColor.normalColor};
NSMutableAttributedString *mAttr = [[NSMutableAttributedString alloc] initWithString:str attributes:attributes];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:6];//行间距
[paragraphStyle setHeadIndent:8];//悬挂缩进
[mAttr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, str.length)];
return mAttr;
}