iOS中Label的首行縮排
阿新 • • 發佈:2019-02-01
NSString *test = @"首行縮排根據字型大小自動調整 間隔可自定根據需求隨意改變。。。。。。。" ; NSMutableParagraphStyle *paraStyle01 = [[NSMutableParagraphStyle alloc] init]; paraStyle.alignment = NSTextAlignmentLeft; //對齊 paraStyle.headIndent = 0.0f;//行首縮排 //引數:(字型大小17號字乘以2,34f即首行空出兩個字元) CGFloat emptylen = self.contentLabel.font.pointSize * 2; paraStyle.firstLineHeadIndent = emptylen;//首行縮排 paraStyle.tailIndent = 0.0f;//行尾縮排 paraStyle.lineSpacing = 2.0f;//行間距 NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:test attributes:@{NSParagraphStyleAttributeName:paraStyle}]; self.contentLabel.attributedText = attrText;