// NSParagraphStyleAttributeName 段落的風格(設置首行,行間距,對齊方式什麼的)看本身須要什麼屬性,寫什麼 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing = 10;// 字體的行間距 paragraphStyle.firstLineHeadIndent = 20.0f;//首行縮進 paragraphStyle.alignment = NSTextAlignmentJustified;//(兩端對齊的)文本對齊方式:(左,中,右,兩端對齊,天然) paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;//結尾部分的內容以……方式省略 ( "...wxyz" ,"abcd..." ,"ab...yz") paragraphStyle.headIndent = 20;//總體縮進(首行除外) paragraphStyle.tailIndent = 20;// paragraphStyle.minimumLineHeight = 10;//最低行高 paragraphStyle.maximumLineHeight = 20;//最大行高 paragraphStyle.paragraphSpacing = 15;//段與段之間的間距 paragraphStyle.paragraphSpacingBefore = 22.0f;// 段首行空白空間 /* Distance between the bottom of the previous paragraph (or the end of its paragraphSpacing, if any) and the top of this paragraph. */ paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight;//從左到右的書寫方向(一共➡️三種) paragraphStyle.lineHeightMultiple = 15;/* Natural line height is multiplied by this factor (if positive) before being constrained by minimum and maximum line height. */ paragraphStyle.hyphenationFactor = 1;//連字屬性 在iOS,惟一支持的值分別爲0和1 /* NSFontAttributeName 字體大小 NSParagraphStyleAttributeName 段落的風格(設置首行,行間距,對齊方式什麼的) NSKernAttributeName 字間距 */ NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:15], NSParagraphStyleAttributeName:paragraphStyle, NSKernAttributeName:@(10), }; textView.attributedText = [[NSAttributedString alloc] initWithString:textView.text attributes:attributes];