整理一下:UILabel字间距

- (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字间距)