Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift Essentials

You're reading from   Swift Essentials Get up and running lightning fast with this practical guide to building applications with Swift

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781784396701
Length 228 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Bandlem Limited Bandlem Limited
Author Profile Icon Bandlem Limited
Bandlem Limited
Alex Blewitt Alex Blewitt
Author Profile Icon Alex Blewitt
Alex Blewitt
Arrow right icon
View More author details
Toc

Creating views by subclassing UIView


Although xib files offer a mechanism to customize classes, the majority of UIKit views outside of standard frameworks are implemented in custom code. This makes it easier to reason what the intrinsic size should be as well as to receive code patches and understand diffs from version control systems. The downside of this approach is when using Auto Layout, writing the constraints can be a challenge and the intrinsic sizes are often misreported or return the unknown value (-1,-1).

A custom view can be implemented as a subclass of UIView. Subclasses of UIView are expected to have two initializers; one that takes frame:CGRect and one that takes a coder:NSCoder. The frame is generally used in code, and the rect specifies the position on screen (0,0 is the top-left) along with the width and height. The coder is used when deserializing from a xib file.

To allow custom subclasses to be used in either interface builder or instantiated from code, it is a best practice...

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 $19.99/month. Cancel anytime
Banner background image