forked from HabitRPG/habitica-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetupCustomizationItemView.swift
73 lines (62 loc) · 1.91 KB
/
SetupCustomizationItemView.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// SetupCustomizationItemView.swift
// Habitica
//
// Created by Phillip on 07.08.17.
// Copyright © 2017 HabitRPG Inc. All rights reserved.
//
import UIKit
class SetupCustomizationItemView: UIView {
@IBOutlet weak var iconView: UIImageView!
@IBOutlet weak var labelView: UILabel!
@IBOutlet weak var borderView: UIView!
var isActive = false {
didSet {
updateViewsForActivity()
}
}
override init(frame: CGRect) {
super.init(frame: frame)
xibSetup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
xibSetup()
}
func xibSetup() {
if let view = loadViewFromNib() {
view.frame = bounds
view.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
addSubview(view)
borderView.layer.borderColor = UIColor.purple400.cgColor
}
}
func loadViewFromNib() -> UIView? {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil)[0] as? UIView
return view
}
func setItem(_ item: SetupCustomization) {
if let icon = item.icon {
iconView.image = icon
}
if let color = item.color {
iconView.backgroundColor = color
}
if let text = item.text {
labelView.text = text
} else {
labelView.isHidden = true
}
}
private func updateViewsForActivity() {
if isActive {
borderView.layer.borderWidth = 4
labelView.textColor = .white
} else {
borderView.layer.borderWidth = 0
labelView.textColor = UIColor.white.withAlphaComponent(0.5)
}
}
}