I know how to set font programmatically when it comes to things like system fonts or custom fonts. But how do I specify the body font style? or caption or headline, for that matter?
Asked
Active
Viewed 1,823 times
3 Answers
1
Here is one way, you can modify it for your need.
attributes:@{NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody]}
For the others, replace body with say headline, etc.

Konsol Labapen
- 2,424
- 2
- 15
- 12
0
You can go for setting attributed string using NSAttributedString.
You alloc and init the NSAttributed string object set the attributes like body fonts and or headline etc.
Moreover, you can set the HTML text in the attributed text.
I hope the following links might help you...
Example of NSAttributedString with two different font sizes?
http://sketchytech.blogspot.in/2013/11/making-most-of-uitextview-in-ios-7.html

Community
- 1
- 1

R_Developer
- 864
- 1
- 7
- 10
0
In Swift, you have to create a font with the class function called preferredFont
from UIFont
:
let label1 = UILabel()
label1.font = UIFont.preferredFont(forTextStyle: .body)
let label2 = UILabel()
label2.font = UIFont.preferredFont(forTextStyle: .caption1)
let label3 = UILabel()
label3.font = UIFont.preferredFont(forTextStyle: .headline)
You can find all the text styles here:

pableiros
- 14,932
- 12
- 99
- 105