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];