Label 根據(jù)文字自動(dòng)調(diào)整大小 以及調(diào)整行間距

Label 根據(jù)文字自動(dòng)調(diào)整Size大小

UILabel *headerLabel = [UILabel new];
    headerLabel.font = [UIFont systemFontOfSize:13];
    NSString *titleContent = @"我們基于十?dāng)?shù)年教育經(jīng)驗(yàn),為“你”打造一套可定制的高效率彈性學(xué)習(xí)系統(tǒng)。我們根據(jù)你的既有經(jīng)驗(yàn)、學(xué)習(xí)速度、能力、弱點(diǎn)和備考時(shí)間進(jìn)行定制,同時(shí)根據(jù)你當(dāng)前計(jì)劃的實(shí)際情況不斷修正下一階段學(xué)習(xí)內(nèi)容;致力于成為你的專屬名師。這一刻,我們最了解你。";
    headerLabel.text = titleContent;
    headerLabel.numberOfLines = 0;//多行顯示,計(jì)算高度
    CGSize titleSize = [titleContent boundingRectWithSize:CGSizeMake(SCREENWIDTH-128*AspW_Iphone6, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil].size;
    headerLabel.size = titleSize;
    headerLabel.x = 0;
    headerLabel.y = image.y+image.height+15*AspH_Iphone6;
    [backGroundView addSubview:headerLabel];

調(diào)整行間距

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:titleContent];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:12];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [titleContent length])];
headerLabel.attributedText = attributedString;
[headerLabel sizeToFit];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容