iOS label行间距和缩进

2016.12.7


NSMutableParagraphStyle*paraStyle = [[NSMutableParagraphStylealloc]init];

paraStyle.lineBreakMode=NSLineBreakByCharWrapping;

paraStyle.alignment=NSTextAlignmentJustified;

paraStyle.lineSpacing=10;//设置行间距

paraStyle.firstLineHeadIndent=10.0;//首行缩进

paraStyle.paragraphSpacingBefore=5.0;//段首行空白空间

paraStyle.headIndent=10.0;//头部缩进,相当于左padding首行除外

paraStyle.tailIndent= -10.0;//相当于右padding

//设置字间距NSKernAttributeName:@1.5f

NSDictionary*dic =@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paraStyle,NSKernAttributeName:@1.5f};

NSAttributedString*attributeStr = [[NSAttributedStringalloc]initWithString:strattributes:dic];

label.attributedText= attributeStr;

你可能感兴趣的:(iOS label行间距和缩进)