iOS UILabel设置行间距

来源:互联网 发布:库存盘点软件 编辑:程序博客网 时间:2024/04/29 20:48
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, Screen_Width, Screen_Height)];    [label setTextColor:[UIColor blackColor]];    [label setNumberOfLines:0];    label.font = [UIFont systemFontOfSize:14.0f];    [label sizeToFit];    NSString *labelText = @"UILabel设置行间距\n行间距为15";    [honorDetailLabel setAttributedText:[self setLineSpacingWith:labelText and:15.0f]];
- (NSMutableAttributedString *)setLineSpacingWith:(NSString *)string and:(CGFloat)spacing{    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:string];    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];    [style setLineSpacing:spacing];    [attributedString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, string.length)];    return attributedString;}

0 0
原创粉丝点击