UITextView文本排版
1.配置NSMutableParagraphStyle
NSMutableParagraphStyle *MParaStyle = [[NSMutableParagraphStyle alloc] init];
MParaStyle.alignment = NSTextAlignmentNatural; // 文字站位
MParaStyle.maximumLineHeight = 20; // 最大高度
MParaStyle.lineHeightMultiple = 10 ; // 平均高度
MParaStyle.minimumLineHeight = 0; // 最小高度
MParaStyle.firstLineHeadIndent = 20; // 首行缩进
MParaStyle.lineSpacing = 0; // 行间距
MParaStyle.headIndent = 20; // 左侧整体缩进
MParaStyle.tailIndent = SCREEN_WIDTH - 20; // 右侧整体缩进
MParaStyle.lineBreakMode = NSLineBreakByCharWrapping; // 内容省略方式
MParaStyle.baseWritingDirection = NSWritingDirectionLeftToRight; // 书写方式
MParaStyle.paragraphSpacingBefore = 0; // 段落之间间距
MParaStyle.paragraphSpacing = 0; // 段落间距离
// MParaStyle.hyphenationFactor = 1; // 连字属性
2.配置attibutes
NSMutableDictionary *attributes = [NSMutableDictionary new];
// 添加paragraphStyle
[attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
// 添加font
[attributes setObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName];
3.关联text
NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"test" attributes:attributes];
UITextView *textView = [[UITextView alloc] init];
[textView setAttributedText:text];
网友评论