Szymon
Szymon

Reputation: 31

Size class for UILabel inside UITableView randomly ignored

I have an UITableView with custom cells which contain UILabels. The text size of labels should be different on iPhone and iPad, so I set different fonts for regular size classes in interface builder.

The problem is that sometimes on iPad font size is not respected and UILabel is displayed with small text size (the one from iPhone). Also, the font size for regular size class is ignored randomly for some table view cells.

Upvotes: 2

Views: 87

Answers (2)

Tim
Tim

Reputation: 583

In my experience, specifying fonts according to size classes is not reliable. What I often do is set the font size to the size that fits the largest size class i.e. iPad, and then downscale the font in autoshrink to a scale that caters to the smallest size class i.e iPhone.

Upvotes: 1

Abd Aboudi
Abd Aboudi

Reputation: 341

I think that you can use this code to identify device size:

 #define iOSVersionGreaterThanOrEqualTo(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

+(NSString*)deviceSize {

CGFloat screenHeight = 0;

if (iOSVersionGreaterThanOrEqualTo(@"8")) {
  screenHeight = MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width);
}else
  screenHeight = [[UIScreen mainScreen] bounds].size.height;

if (screenHeight == 480)
  return "Screen 3.5 inch";
else if(screenHeight == 568)
  return "Screen 4 inch";
else if(screenHeight == 667){
  if ([UIScreen mainScreen].scale > 2.9) return Screen5Dot5inch;
    return  "Screen 4.7 inch";
}else if(screenHeight == 736)
  return "Screen 5.5 inch";
else
  return "UnknownSize";
}

Upvotes: 1

Related Questions