WEB开发网
开发学院手机开发iPhone 开发 设置IOS的UILabel动态高度方法 阅读

设置IOS的UILabel动态高度方法

 2013-06-19 16:09:34 来源:WEB开发网   
核心提示: 开始的时候按钮事件中,可能写的是这样一段代码:if (isExpand) {[lblBrief setNumberOfLines:2];lblBrief.text = [StringUtil subString:strBrief AndSubLength:90];[btnBrief setImage:[UIImage

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


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


}

Tags:设置 IOS UILabel

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接