美文网首页
整理一下:UILabel字间距

整理一下:UILabel字间距

作者: 西门欥雪 | 来源:发表于2018-05-24 12:34 被阅读1212次
    - (void)viewDidLoad {
       [super viewDidLoad];
    
        NSString * text = @"这是测试UILabel行间距的text。这是测试  UILabel行间距的text。n 这UILabel行间距的text. 这是测试UILabel行间距的text。这是测试UILabel行间距的text。这是测试UILabel行间距的text。这是测试UILabel行间距的获取text传入固定宽度,获取text传入固定宽度获取获取text传入固定宽度,获取text传入固定宽度fff";
    
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10,       20, WIDTH-20, 200)];
    
        label.numberOfLines = 0;
    
        label.backgroundColor = [UIColor greenColor];
    
        label.font = FONT(15);
    
        label.lineBreakMode = NSLineBreakByCharWrapping;
    
        //设置字间距
        NSDictionary *dic = @{NSKernAttributeName:@10.f};
        NSMutableAttributedString * attributedString =     [[NSMutableAttributedString alloc] initWithString:text attributes:dic];
    
        NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc]     init];
    
        [paragraphStyle setLineSpacing:30];//行间距
    
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
        [label setAttributedText:attributedString];
        [label sizeToFit];
        [self.view addSubview:label];
    }

    相关文章

      网友评论

          本文标题:整理一下:UILabel字间距

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