ios  调整 label 的字体行间距

 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 200)];
    [label setBackgroundColor:[UIColor blackColor]];
    [label setTextColor:[UIColor whiteColor]];
    [label setNumberOfLines:0];
   
    NSString *labelText = @"可以自己按照宽高,字体大小,来计算有多少行。。然后。。。每行画一个UILabel。。高度自己可以控制把这个写一个自定义的类。 ";
   
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
   
    [paragraphStyle setLineSpacing:10];//调整行间距
   
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
    label.attributedText = attributedString;
    [self.view addSubview:label];
    [label sizeToFit];
   
    NSLog(@"%f %f",label.frame.size.width,label.frame.size.height);
posted @ 2017-03-22 16:13  Dingzhijie  阅读(3706)  评论(0编辑  收藏  举报