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

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

EventAddresslabel=[[UILabelalloc]initWithFrame:CGRectMake(starttimelabel.frame.origin.x, starttimelabel.frame.origin.y+distance,270,20)];

EventAddresslabel.backgroundColor=[UIColorclearColor];

EventAddresslabel.textColor=[UIColorwhiteColor];

EventAddresslabel.font=[UIFontsystemFontOfSize: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=[NSStringstringWithFormat:@"%@ %@,%@",cassetInfo.eventAddress,cassetInfo.city,cassetInfo.state];

[uiviewaddSubview:EventAddresslabel];

CGSizeEventAddresslabelsize = [EventAddresslabel.textsizeWithFont:[UIFontsystemFontOfSize:15] constrainedToSize:CGSizeMake(285, [EventAddresslabel.textlength])lineBreakMode:UILineBreakModeWordWrap];

[EventAddresslabelsetFrame:CGRectMake(EventAddresslabel.frame.origin.x,EventAddresslabel.frame.origin.y, 290,EventAddresslabelsize.height+10)];


Description=[[UILabelalloc]initWithFrame:CGRectMake(5,EventAddresslabel.frame.origin.y+EventAddresslabel.frame.size.height,320,60)];

DescriptionactivityView= [[UIActivityIndicatorViewalloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

DescriptionactivityView.frame=CGRectMake(140.f,EventAddresslabel.frame.origin.y+30,30.0f,30.0f);

Londinglabel_1=[[UILabelalloc]initWithFrame:CGRectMake(132,Description.frame.origin.y+30,80,20)];

Labelflag=0;

Description.backgroundColor=[UIColorclearColor];

Description.textColor=[UIColorwhiteColor];

Description.font=[UIFontsystemFontOfSize:15];

Description.numberOfLines=0;

Description.lineBreakMode=UILineBreakModeWordWrap;

[uiviewaddSubview:Description];

你可能感兴趣的:(在一个label中显示多行,自动换行)