下面文章转载自http://wangjun.easymorse.com/?m=201106
UILable显示文字,大多数情况下文字是动态的,所以UILable的大小需要自适用,下面是实现的具体代码:
myLable=[[UILabel alloc] initWithFrame:CGRectMake(0, 23, 175, 33)];
[myLable setFont:[UIFont fontWithName:@"Helvetica" size:10.0]];
[myLable setNumberOfLines:0];
[myLable setBackgroundColor:[UIColor clearColor]];
[myAdView addSubview:myLable];UIFont *font = [UIFont fontWithName:@"Helvetica" size:10.0];
CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(175.0f, 2000.0f) lineBreakMode:UILineBreakModeWordWrap];
CGRect rect=myLable.frame;
rect.size=size;
[myLable setFrame:rect];
[myLable setText:text];