设置ios的uilabel动态高度方法
2014-12-08来源:

开始的时候按钮事件中,可能写的是这样一段代码:

if (isexpand) {

[lblbrief setnumberoflines:2];

lblbrief.text = [stringutil substring:strbrief andsublength:90];

[btnbrief setimage:[uiimage imagenamed:@detailbriefdown] forstate:uicontrolstatenormal];

[btnbrief setimage:[uiimage imagenamed:@detailbriefdown] forstate:uicontrolstatehighlighted];

}else{

[lblbrief setnumberoflines:0];

lblbrief.text = strbrief;

[btnbrief setimage:[uiimage imagenamed:@detailbriefup] forstate:uicontrolstatenormal];

[btnbrief setimage:[uiimage imagenamed:@detailbriefup] forstate:uicontrolstatehighlighted];

}

可以通过setnumberoflines:0,来让概述的所以内容显示出来,但如果,不计算所要显示全部内容的总高度,label的宽高是不会自动增大的。

else{

[lblbrief setnumberoflines:0];

lblbrief.text = strbrief;

cgsize constraint = cgsizemake(self.view.frame.size.width - (15 * 2), 20000.0f);

cgsize size = [strbrief sizewithfont:[uifont systemfontofsize:10]constrainedtosize:constraint linebreakmode:uilinebreakmodewordwrap];

[brief setframe:cgrectmake(15,160,size.width,size.height)];

[btnbrief setimage:[uiimage imagenamed:@detailbriefup]forstate:uicontrolstatenormal];

[btnbrief setimage:[uiimage imagenamed:@detailbriefup]forstate:uicontrolstatehighlighted];

}

更多信息请查看IT技术专栏

推荐信息
Baidu
map