Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Geri-Borbas/iOS.Blog.UILabel_Typography_Extensions

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

48 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

UILabel Typography Extensions ๐Ÿ“

Set UILabel line height, letter spacing (and more).

let headerLabel = UILabel()
headerLabel.textColor = UIColor(named: "Mars")
headerLabel.font = UIFont(name: "HelveticaNeue-CondensedBlack", size: 100)
headerLabel.lineHeight = 80
headerLabel.letterSpacing = 100 * -0.02
headerLabel.text = "Mars"

See the complementary article at UILabel line height, letter spacing and more UILabel typography extensions.

How it works

It is an extension on UILabel that adds some typographic properties using Objective-C Runtime (for stored properties on a Swift extension), NSAttributedString (for manage typographic properties), and NSKeyValueObservation (to be able to use the regular text property to manage text content).

It also takes care of baselineOffset values to keep the text content in the vertical center (right). By default, NSAttributedString sticks multiline label content to the top of the container view (left), which makes it hard to match the UI with the design specifications.

Using this extension you can build screens that 100% match design specifications. More on that in the article at UILabel line height, letter spacing and more UILabel typography extensions.

License

Licensed under the MIT License.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.