I am using Constrain for ipad and iphone.. so now i want to change button font size (wC hR) prograamatically.
Asked
Active
Viewed 548 times
1
-
http://stackoverflow.com/questions/1465305/set-uibutton-title-uilabel-font-size-programmatically – Skywalker Nov 02 '15 at 05:06
2 Answers
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
-
-
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
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.