//給UILabel設置行間距和字間距
-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font
{
NSMutableParagraphStyle *pStyle = [[NSMutableParagraphStyle alloc] init];
pStyle.lineBreakMode = NSLineBreakByCharWrapping;
pStyle.alignment = NSTextAlignmentLeft;
pStyle.lineSpacing = UILABEL_LINE_SPACE; //設置行間距
pStyle.hyphenationFactor = 1.0;
pStyle.firstLineHeadIndent = 0.0;
pStyle.paragraphSpacingBefore = 0.0;
pStyle.headIndent = 0;
pStyle.tailIndent = 0;
//設置字間距 1.5f
NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:pStyle, NSKernAttributeName:@1.5f
};
NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
label.attributedText = attributeStr;
}
複製代碼