IOS UILabel 根据内容自适应高度
iOS Label 自適應高度? 適配iOS7以后的版本
更多? ? self.contentLabelView = [[UILabel alloc] init];
? ? self.contentLabelView.font = SYS_FONT(15);
? ? self.contentLabelView.lineBreakMode =NSLineBreakByTruncatingTail ;
? ? self.contentLabelView.textColor =? [UIColor colorWithHexString:@"#444444"];
? ? self.contentLabelView.text =[@"12312312312312321321dddsdadsadasdasdas" stringByAppendingString:@"\n\n\n\n\n\n\n"];
? ? [self.contentLabelView setNumberOfLines:0];
?? ?
? ? //根據內容計算出label所需要的高度
??? CGSize size = CGSizeMake(kScreenWidth - expectSizes.width-20, MAXFLOAT);
? ? NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:self.contentLabelView.font,NSFontAttributeName,nil];
? ? CGSize? actualsize =[self.contentLabelView.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin? attributes:tdic context:nil].size;
? ? self.contentLabelView.frame =CGRectMake(expectSizes.width+20, 254, actualsize.width, actualsize.height);
?
純代碼布局可能會用到,不過推薦使用xib或storyboard。
轉載于:https://www.cnblogs.com/wangmars/p/5729716.html
總結
以上是生活随笔為你收集整理的IOS UILabel 根据内容自适应高度的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 缓存(CDN缓存,浏览器(客户端)缓存)
- 下一篇: SGML DTD