iOS //给UILabel设置行间距和字间距

2016.9.8



//给UILabel设置行间距和字间距

-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {

NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];

paraStyle.lineBreakMode =NSLineBreakByCharWrapping;

paraStyle.alignment = NSTextAlignmentLeft;

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

paraStyle.hyphenationFactor = 0.3;

paraStyle.firstLineHeadIndent =0.0;

paraStyle.paragraphSpacingBefore =0.0;

paraStyle.headIndent = 0;

paraStyle.tailIndent = 0;

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

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

};

NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];

label.attributedText = attributeStr;

}

你可能感兴趣的:(iOS //给UILabel设置行间距和字间距)