日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

IOS UILabel 根据内容自适应高度

發(fā)布時(shí)間:2025/4/16 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS UILabel 根据内容自适应高度 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

iOS Label 自適應(yīng)高度? 適配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];

?? ?

? ? //根據(jù)內(nèi)容計(jì)算出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);

?

純代碼布局可能會(huì)用到,不過推薦使用xib或storyboard。

轉(zhuǎn)載于:https://www.cnblogs.com/wangmars/p/5729716.html

總結(jié)

以上是生活随笔為你收集整理的IOS UILabel 根据内容自适应高度的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。