Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning iOS UI Development

You're reading from  Learning iOS UI Development

Product type Book
Published in Dec 2015
Publisher
ISBN-13 9781785288197
Pages 196 pages
Edition 1st Edition
Languages

The UIAppearance protocol


If there's one thing the controls we've talked about so far have in common, it is that they can be graphically customized with the use of simple functions. This is a great a feature that has been added to UIKit since iOS5, and it allows us to modify the looks of any default control with just a few lines of code.

This feature is improved by the UIAppearance protocol that, thanks to the appearance proxy, forwards the customizations to all the instances of a specific class. The appearance proxy for a class can be retrieved using the appearance function, and as it returns instancetype, its properties can be easily accessed. Here is an example of the code needed to set onTintColor for all the UISwitch instances of an application:

UISwitch.appearance().onTintColor = UIColor.redColor()

The properties that take part in the UIAppearance protocol and can therefore be modified through the appearance proxy must be marked with the UI_APPEARANCE_SELECTOR tag. This portion of the...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}