-
Notifications
You must be signed in to change notification settings - Fork 872
/
Copy pathIceCreamView.swift
34 lines (27 loc) · 1.14 KB
/
IceCreamView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
A `UIStackView` containing the parts of a given `IceCream`.
*/
import UIKit
class IceCreamView: UIStackView {
var iceCream: IceCream? {
didSet {
// Remove any existing arranged subviews.
for view in arrangedSubviews {
removeArrangedSubview(view)
}
// Do nothing more if the `iceCream` property is nil.
guard let unwrappedIceCream = iceCream else { return }
// Add a `UIImageView` for each of the ice cream's valid parts.
let iceCreamParts: [IceCreamPart?] = [unwrappedIceCream.topping, unwrappedIceCream.scoops, unwrappedIceCream.base]
for iceCreamPart in iceCreamParts {
guard let iceCreamPart = iceCreamPart else { continue }
let imageView = UIImageView(image: iceCreamPart.image)
imageView.contentMode = .scaleAspectFit
addArrangedSubview(imageView)
}
}
}
}