Creating a Custom Control
Open Mandala.xcodeproj and create a new Swift file named ImageSelector. Define a new UIControl subclass within this file.
Listing 18.1 Creating the ImageSelector
class (ImageSelector.swift
)
import Foundationimport UIKit class ImageSelector: UIControl { }
The interface for this control will be set up much like the existing stack view of buttons. The primary difference, in terms of code, is that the ImageSelector will not be tied directly to the array of emoji images. Instead, it will hold on to an arbitrary array of images, allowing the control to be flexible and reusable.
Let’s start re-creating the interface. Add a property for a horizontal stack view and configure some of its attributes. ...
Get iOS Programming: The Big Nerd Ranch Guide, 7th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.