swift
Specific font
Installing a specific font in Swift is done as follows:
let myFont = UIFont(name: "Helvetica", size: 17)
If you do not know the name, you can get a list of available font names, for example:
print(UIFont.familyNames())
Or an even more detailed list:
for familyName in UIFont.familyNames() { print(UIFont.fontNamesForFamilyName(familyName)) }
But the system font is changing from version to version of iOS. So it would be better to get the system font dynamically.
System font
let myFont = UIFont.systemFontOfSize(17)
But we have a hard-coded size. What if the user has bad eyes and they want to increase the font? Of course, you could make a setting in your application so that the user changes the font size, but it will be annoying if the user has to do this separately for each application on his phone. It would be easier to make one change in the general settings ...
Dynamic font
let myFont = UIFont.preferredFont(forTextStyle: .body)
Ah, now we have a system font with a user-selected size for the text style we are working with. This is the recommended way to install the font. See Supportive Dynamic Type for more information about this.
connected with
- IOS visual font list
- How to make an attribute string using Swift?
Suragch Jan 16 '16 at 10:55 2016-01-16 10:55
source share