UITextView实际上是一个UIScrollView,因此获取contentSIze里的height属性即可
-
UITextView *tv=[[UITextView alloc]initWithFrame:CGRectMake(0,0,1024, 0)];
-
tv.text=@"第一行\n第二行\n第三行";
-
[detailView addSubview:tv];
-
CGRect rect=tv.frame;
-
rect.size.height=tv.contentSize.height;
-
tv.frame=rect;
-
[tv release];
UILabel比较麻烦
-
UILabel *detailText=[[UILabel alloc]initWithFrame:CGRectMake(0,daText.frame.size.height+daText.frame.origin.y,1024, 0)];
-
detailText.backgroundColor=[UIColor blackColor];
-
detailText.textColor=[UIColor whiteColor];
-
detailText.font = [UIFont fontWithName:@"汉仪大黑简" size:13];
-
detailText.numberOfLines=0;
-
detailText.textAlignment = UITextAlignmentLeft;
-
detailText.lineBreakMode = UILineBreakModeWordWrap;
-
[detailView addSubview:detailText];
-
-
detailText.text=info.answer;
-
CGSize expectedLabelSize = [detailText.text sizeWithFont:detailText.font
-
constrainedToSize:detailText.frame.size
-
lineBreakMode:UILineBreakModeWordWrap];
-
-
CGRect rect2 = detailText.frame;
-
rect2.size.height = expectedLabelSize.height;
-
rect2.size.width=1024;
-
detailText.frame=rect2;
-
[detailText sizeToFit];
-
if (detailText.frame.size.width<1024) {
-
CGRect rect2 = detailText.frame;
-
rect2.size.width=1024;
-
detailText.frame=rect2;
-
}
-
[detailView release];
阅读(3613) | 评论(0) | 转发(0) |