美文网首页
iOS Label设置行间距

iOS Label设置行间距

作者: 全村的希望iOS | 来源:发表于2019-11-12 14:16 被阅读0次

    -(void)setLabelSpace:(UILabel*)label withSpace:(CGFloat)space withFont:(UIFont*)font {

            NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];

            paraStyle.lineBreakMode = NSLineBreakByCharWrapping;

            paraStyle.alignment = NSTextAlignmentLeft;

            paraStyle.lineSpacing = space; //设置行间距

            paraStyle.hyphenationFactor = 1.0;

            paraStyle.firstLineHeadIndent = 0.0;

            paraStyle.paragraphSpacingBefore = 0.0;

            paraStyle.headIndent = 0;

            paraStyle.tailIndent = 0;

            //设置字间距 NSKernAttributeName:@1.5f

            NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@0.0f

                                  };

            NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:label.text attributes:dic];

            label.attributedText = attributeStr;

    }

    相关文章

      网友评论

          本文标题:iOS Label设置行间距

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