富文字中的段落屬性

滴水微瀾發表於2016-04-04
//   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];

相關文章