我有以下代码来计算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;
在iOS 5.1.1中,locationTextHeight
为88,moreInfoTextHeight
= 52.在iOS 6中,高度分别为1420和2482.
为什么iOS 6中的高度不同,我该如何解决这个问题呢?
答案 0 :(得分:2)
问题是由于没有用框架初始化UITextView引起的。
UITextView *locationText = [[UITextView alloc] initWithFrame:CGFrameMake(0,0,200,20)];
UITextView *moreInfoText = [[UITextView alloc] initWithFrame:CGFrameMake(0,0,200,20)];
在iOS 6之前,UITextView必须有一个宽度大于0的默认框架。