美文网首页PerhapYs的OC学习日记UI基础
iOS开发-UITextView文字排版

iOS开发-UITextView文字排版

作者: PerhapYs | 来源:发表于2016-01-04 19:41 被阅读1199次

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];

相关文章

网友评论

    本文标题:iOS开发-UITextView文字排版

    本文链接:https://www.haomeiwen.com/subject/ovrahttx.html