在一个label中显示多行,自动换行


在active.com的开发项目中,遇到一个动态显示detail page的问题。取的数据有的时候多有的时候少,而且还需要自动换行。计算行的高度,text的长度,大小等。



EventAddresslabel=[[UILabel alloc]initWithFrame:CGRectMake(starttimelabel.frame.origin.x,   starttimelabel.frame.origin.y+distance, 270, 20)];
EventAddresslabel.backgroundColor=[UIColor clearColor];
EventAddresslabel.textColor=[UIColor whiteColor];
EventAddresslabel.font=[UIFont systemFontOfSize:15];
EventAddresslabel.numberOfLines =0; //this is used to determine how many lines this label will have.if =3,it means this     label's text will show 3 lines.if =0 ,it means that this label's text will show the line whate it needs.no limit.
EventAddresslabel.lineBreakMode = UILineBreakModeWordWrap;// sys will change the line by word.aslo can be by character  for another value.
EventAddresslabel.text=[NSString stringWithFormat:@"%@  %@,%@",cassetInfo.eventAddress,cassetInfo.city,cassetInfo.state];
[uiview addSubview:EventAddresslabel];
     
CGSize EventAddresslabelsize = [EventAddresslabel.text sizeWithFont:[UIFont systemFontOfSize:15]    constrainedToSize:CGSizeMake(285, [EventAddresslabel.text length])lineBreakMode:UILineBreakModeWordWrap];
[EventAddresslabel setFrame:CGRectMake(EventAddresslabel.frame.origin.x,EventAddresslabel.frame.origin.y,   290,EventAddresslabelsize.height+10)];
 
Description=[[UILabel alloc]initWithFrame:CGRectMake(5,EventAddresslabel.frame.origin.y+EventAddresslabel.frame.size.height, 320, 60)];
DescriptionactivityView = [[UIActivityIndicatorView alloc]  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
DescriptionactivityView.frame = CGRectMake(140.f, EventAddresslabel.frame.origin.y+30, 30.0f,30.0f);
Londinglabel_1=[[UILabel alloc]initWithFrame:CGRectMake(132, Description.frame.origin.y+30, 80,20)];
Labelflag=0;
Description.backgroundColor=[UIColor clearColor];
Description.textColor=[UIColor whiteColor];
Description.font=[UIFont systemFontOfSize:15];
Description.numberOfLines =0;
Description.lineBreakMode = UILineBreakModeWordWrap;
[uiview addSubview:Description];
//该代码片段来自于: http://www.sharejs.com/codes/objectc/2000
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值