UILabel设置行间距和字间距

#define UILABEL_LINE_SPACE 6
#define HEIGHT [ [ UIScreen mainScreen ] bounds ].size.height
//给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;
}

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