Xcode 6 has a new feature where fonts and font sizes in UILabel
, UITextField
, and UIButton
can be s
I've come up with even faster fix (I assume you always use your one custom font).
Create a category for UILabel and include in files using buggy storyboard with size classes and dedicated font setting for various classes:
@implementation UILabel (FontFixForSizeClassesAppleBug)
- (void)layoutSubviews
{
[super layoutSubviews];
if([[UIFont systemFontOfSize:10].familyName isEqualToString:self.font.familyName]) {
//workaround for interface builder size classes bug which ignores custom font if various classes defined for label: http://stackoverflow.com/questions/26166737/custom-font-sizing-in-xcode6-size-classes-not-working-properly-w-custom-fonts
self.font = [UIFont fontWithName:@"YOUR_CUSTOM_FONT_NAME" size:self.font.pointSize];
}
}
@end
Just use your custom fonts in storyboard. When buggy interpreter will use system font instead your own this category will switch it to your custom font.
I had the same problem and found one not really clear, but fine solution!
override func viewDidLayoutSubviews() { for i in 100...110 { if let label = view.viewWithTag(i) as? UILabel { label.font = UIFont(name: "RotondaC-Bold", size: label.font.pointSize) } } }
Similar solution to @razor28's one but I think a little more universal. Also, works fine on older iOS versions
https://gist.github.com/softmaxsg/8a3ce30331f9f07f023e
Workaround for UILabel
: keep the same font size on all Size Classes, but instead change your label height accordingly in each Size Class. Your label must have autoshrink enabled. It worked nicely in my case.
This (and other Xcode - Size Classes related) bug caused me some serious grief recently as I had to go through a huge storyboard file hacking things away.
For anyone else in this position, I'd like to add something on top of @razor28's answer to ease the pain.
In the header file of your custom subclass, use IBInspectable
for your runtime attributes. This will make these attributes accessible from the "Attributes Inspector", visually right above the default position for font settings.
Example use:
@interface MyCustomLabel : UILabel
@property (nonatomic) IBInspectable NSString *fontType;
@property (nonatomic) IBInspectable CGFloat iphoneFontSize;
@property (nonatomic) IBInspectable CGFloat ipadFontSize;
@end
This will very helpfully produce this output:
An added benefit is that now we don't have to add the runtime attributes manually for each label. This is the closest I could get to XCode's intended behaviour. Hopefully a proper fix is on its way with iOS 9 this summer.
The problem is still there that you cannot use the feature to set Fonts for different size classes from interface builder.
Just set font based on the device you want just like below:
if (Your Device is iPAd) //For iPad
{
[yourLabel setFont:[UIFont fontWithName:@"FontName" size:FontSize]];
}
else //For Other Devices then iPad
{
[yourLabel setFont:[UIFont fontWithName:@"FontName" size:FontSize]];
}
This works perfectly on all devices.