Reputation: 201
I am using a custom font and I want it to be customised using storyboard and size class. I want to vary it according to screen size of iPad and iPhone, smaller the screen size smaller the font size. But its not changing if I am using this custom font. I am using Xcode 7.
Upvotes: 0
Views: 1024
Reputation: 654
Use the below code:
class MyCustomLabel: UILabel {
override func layoutSubviews() {
self.font = UIFont.init(name: “YourCustomFont", size: self.font.pointSize)
}
}
Actually self.font.pointSize :- This will help you fetching the font size from the Storyboard (whatever you have set with System font.)
Upvotes: 1
Reputation: 238
In Storyboard select the label you want to scale
Please find the below picture
More over from my point all of the iphone devices comes with quality pixels so this affect only a pinch level
you can't expect in ipone x -40size -> iphone 5 - 35size
but if your using device logic you can set whatever size you need to set for iphone 5 and iphone x
this will help you
How to determine the current iPhone/device model?
use the link above and create extension then call the extension like below
modelName = UIDevice.current.modelName
switch modelName {
case "iPhone SE" , "iPhone 5" , "iPhone 5c" , "iPhone 5s" :
titleLabel.font = UIFont(name : "Vollkorn-Regular" , size : 20.0)
name.font = UIFont(name : "OpenSans-SemiBold" , size : 12.0)
print("i 5 series")
break
case "iPhone 8 Plus" :
titleLabel.font = UIFont(name : "Vollkorn-Regular" , size : 24.0)
name.font = UIFont(name : "OpenSans-SemiBold" , size : 16.0)
print("i 8 series")
break
default:
break
}
Upvotes: 1
Reputation: 2425
You need a dynamic font size and width and for that you have to implement this two line of code -
labelName.adjustsFontSizeToFitWidth = true
labelName.minimumScaleFactor = 0.3
And from your story board, change the lines of the label to 0-
Or programmatically you can add this line of code -
labelName.numberOfLines = 0 // or you can set it 1 or 2
Upvotes: 1