NSAttributedString之设置字间距与行间距

    // 调整行间距
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:textStr];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:3];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [textStr length])];
// 调整字间距 long number = 1.5; CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt8Type,&number); [attributedString addAttribute:(id)kCTKernAttributeName value:(__bridge id)num range:NSMakeRange(0,[attributedString length])];

  sizeToFit后控件的高度是sizeWithFont:constrainedToSize:算出的1~N倍,醉了~

 
 
 
如有疑问,共同探讨,共同进步。
原文地址:https://www.cnblogs.com/nielsen/p/4836610.html