Anthony
Anthony

Reputation: 1714

UITextView ContentSize.Height too high on iOS 6

I have the following code to calculate the height of a UITableView cell.

  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.

Why are the heights different in iOS 6 and how can I fix the issue?

Upvotes: 0

Views: 1083

Answers (1)

Anthony
Anthony

Reputation: 1714

The problem was caused by not initializing the UITextView with a frame.

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.

Upvotes: 2

Related Questions