We can use Playgrounds to experiment with UI and test custom views and interfaces. In this recipe, we will build a bar chart view that we can use to display numerical data in chart form and use a playground to test it.
Getting ready
First, we'll create an iOS-based playground to build our bar chart. In Chapter 1, Swift Building Blocks, we went through creating a new playground, so return there if you need a refresher.
We will create a custom view that will display information in bar chart form, and use that to test some features of playgrounds. You can either enter the following code into a new iOS-based playground or download the playground named Simple_iOS.playground from this book's GitHub repository:
- Create a Color struct:
import UIKit
struct Color {
let red: Float
let green: Float
let blue: Float
let alpha: Float = 1.0
var displayColor: UIColor {
return UIColor(red: CGFloat(red),
green: CGFloat...