美文网首页iOS开发
UILabel设置行间距和字间距

UILabel设置行间距和字间距

作者: Pandakingli | 来源:发表于2017-03-18 21:03 被阅读135次
#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设置行间距和字间距

    本文链接:https://www.haomeiwen.com/subject/eyjpnttx.html