设置label的行间距

1.首先,label不能只有一行

//限制行数
    label.numberOfLines=0;

2.设置字行间距

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 10;// 字体的行间距
    int notDown = 0;
    for (NSString * ss in _TotalTest_stasus) {
        if ([ss isEqualToString:@"0"]) {
            notDown++;
        }
    }
    NSDictionary *attributes = @{
                                 NSFontAttributeName:SLLFONT(14),
                                 NSParagraphStyleAttributeName:paragraphStyle
                                 };
    ContentLabel.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"您还有%d题未作答,确定放弃本次考试吗?",notDown] attributes:attributes];

3.同样的方法也适用于textview

你可能感兴趣的:(设置label的行间距)