NSParagraphStyle - 段落设置
2021-12-25 本文已影响0人
杨继磊
偶尔用到了一下,顺便做个笔记。
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.lineSpacing = 20.;// 行间距
paragraphStyle.lineHeightMultiple = 1.5;// 行高倍数(1.5倍行高)
paragraphStyle.firstLineHeadIndent = 30.0f;//首行缩进
paragraphStyle.minimumLineHeight = 10;//最低行高
paragraphStyle.maximumLineHeight = 20;//最大行高(会影响字体)
paragraphStyle.alignment = NSTextAlignmentLeft;// 对齐方式
paragraphStyle.defaultTabInterval = 144;// 默认Tab 宽度
paragraphStyle.headIndent = 20;// 起始 x位置
paragraphStyle.tailIndent = 320;// 结束 x位置(不是右边间距,与inset 不一样)
paragraphStyle.paragraphSpacing = 44.;// 段落间距
paragraphStyle.paragraphSpacingBefore = 44.;// 段落头部空白(实测与上边的没差啊?)
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;// 分割模式
/*
NSLineBreakByWordWrapping = 0, // Wrap at word boundaries, default
NSLineBreakByCharWrapping, // Wrap at character boundaries
NSLineBreakByClipping, // Simply clip
NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz"
NSLineBreakByTruncatingTail, // Truncate at tail of line: "abcd..."
NSLineBreakByTruncatingMiddle // Truncate middle of line: "ab...yz"
*/
paragraphStyle.baseWritingDirection = NSWritingDirectionRightToLeft;// 段落方向
/*
NSWritingDirectionNatural = -1, // Determines direction using the Unicode Bidi Algorithm rules P2 and P3
NSWritingDirectionLeftToRight = 0, // Left to right writing direction
NSWritingDirectionRightToLeft = 1
*/