[英]UITextView ContentSize.Height too high on iOS 6
I have the following code to calculate the height of a UITableView cell. 我有以下代码来计算UITableView单元格的高度。
UIFont *textFont = [SettingsManagerUI defaultFontItalicWithSize:14];
UIView *tempView = [[UIView alloc] init];
UITextView *locationText = [[UITextView alloc] init];
UITextView *moreInfoText = [[UITextView alloc] init];
[tempView addSubview:locationText];
[tempView addSubview:moreInfoText];
[locationText setFont:textFont];
[moreInfoText setFont:textFont];
NSString *locationDetails = [MembersSavePartnerDetailsMoreInfoTableCell generateLocationTextWithPartner:partner inLocation:location];
locationText.text = locationDetails;
NSString *moreInfo = partner ? partner.partnerDescription : location.partner.partnerDescription;
moreInfoText.text = moreInfo;
float locationTextHeight = locationText.contentSize.height;
float moreInfoTextHeight = moreInfoText.contentSize.height;
In iOS 5.1.1, the locationTextHeight
is 88 and the moreInfoTextHeight
= 52. In iOS 6, the heights are 1420 and 2482 respectively. 在iOS 5.1.1中,
locationTextHeight
为88, moreInfoTextHeight
= 52.在iOS 6中,高度分别为1420和2482。
Why are the heights different in iOS 6 and how can I fix the issue? 为什么iOS 6中的高度不同,我该如何解决这个问题?
The problem was caused by not initializing the UITextView with a frame. 问题是由于没有用框架初始化UITextView引起的。
UITextView *locationText = [[UITextView alloc] initWithFrame:CGFrameMake(0,0,200,20)];
UITextView *moreInfoText = [[UITextView alloc] initWithFrame:CGFrameMake(0,0,200,20)];
Before iOS 6, the UITextView must have had a default frame with a width greater than 0. 在iOS 6之前,UITextView必须具有宽度大于0的默认帧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.