Creating a Custom View
I am adding a 5 star rating system to the meal tracker app. I will use a custom control that will hold and display the logic required. Essentially, I create a UIStackView
subclass to create an independant, modularized view that can be injected independantly into any view.
So far, I have the ugly red button but I will eventually have clickable stars in its place with event handlers tied to the view controller
.
Key concepts
Adding Initializer Placeholders
init(Frame:)
- initializes and returns a newly allocated view object with the specified frame rectangle
Archiving and Serialization
Convert objects and values to and from property list, JSON, and other flat binary representations
NSCoding
- a protocol that enables an object to be encoded and decoded for archiving and distribution
Adding buttons to the Custom Control
UIButton()
- convenience initializer that calls init(frame:)
and passes in a zero-sized rectangle.