1

enter image description here

I am using Constrain for ipad and iphone.. so now i want to change button font size (wC hR) prograamatically.

Hitesh Boricha
  • 114
  • 1
  • 11

2 Answers2

1
let wSize = self.view.traitCollection.horizontalSizeClass
let hSize = self.view.traitCollection.verticalSizeClass

if wSize == UIUserInterfaceSizeClass.Compact && hSize == UIUserInterfaceSizeClass.Regular {
    button.titleLabel?.font = UIFont(name: FontNameCode, size: size)
}
Tim
  • 2,089
  • 1
  • 12
  • 21
  • I am using Objective C. Can u please provide me code on it? – Hitesh Boricha Nov 02 '15 at 03:56
  • Sorry, I missed that tag in your post. I really don't know Obj-C well enough to convert it. But you're just creating two `UIUserInterfaceSizeClass` objects, then checking to see if they are the right size. – Tim Nov 02 '15 at 04:02
1

Set Font Size as below.

Step 1: Set fonts as System for size classes

enter image description here

Step 2: Subclass UILabel and override "layoutSubviews" method like:

- (void)layoutSubviews
{
  [super layoutSubviews];
  // Implement font logic depending on screen size
  self.font = [UIFont systemFontOfSize:self.font.pointSize];
}

May be it will help you.