设置label 的 字间距 和行间距

 
    // 设置 文字间距
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    NSMutableAttributedString *attributedString =  [[NSMutableAttributedString alloc] initWithString:MiaoShuLabel.text attributes:@{NSKernAttributeName : @(1.5f)}];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, MiaoShuLabel.text.length)];
    MiaoShuLabel.attributedText = attributedString;
  // 设置 行间距
    [paragraphStyle setLineSpacing:3];
   
    CGSize maxSize = CGSizeMake(SCRREEN_WIDTH -20, 2000);
    NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc]init];
    paragraph.lineBreakMode = NSLineBreakByWordWrapping;
    CGSize labelSize = [MiaoShuLabel sizeThatFits:maxSize];
     MiaoShuLabel.frame = CGRectMake(10, 500, SCREEN_WIDTH- 20, labelSize.height);

你可能感兴趣的:(iOS,开发)