Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom font with size classes in iOS

I'm trying to add 2 different font sizes for iphone and ipad layouts using size classes. It works cool with a default System font but doesn't work with custom font(I'm using PragmataPro in my project). If I add the second size for wR hR then font looks correctly in interface builder(I even checked xml) but in simulator and on device it becomes System instead of PragmataPro. But if I remove wR hR(or whatever layout I'm using for another size) then font shows correctly. Any idea how to solve this issue? Thanks!

like image 207
Dmytro Nasyrov Avatar asked Oct 05 '14 14:10

Dmytro Nasyrov


1 Answers

Subclass UILabel and override "layoutSubviews" method like:

- (void)layoutSubviews
{
 [super layoutSubviews];
 // Implement font logic depending on screen size
  self.font = [UIFont fontWithName:@"CustomFont" size:self.font.pointSize];
}
like image 138
Shruti Avatar answered Nov 01 '22 18:11

Shruti