-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathPasswordItemView.swift
More file actions
60 lines (44 loc) · 1.38 KB
/
PasswordItemView.swift
File metadata and controls
60 lines (44 loc) · 1.38 KB
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
//
// PasswordItemView.swift
// Demo
//
// Created by Jinsei Shima on 2018/11/17.
// Copyright © 2018 Jinsei Shima. All rights reserved.
//
import UIKit
import PinCodeInputView
final class PasswordItemView: UIView, ItemType {
var isSecureText: Bool = false
var text: Character? = nil {
didSet {
guard let _ = text else {
backgroundColor = .clear
return
}
backgroundColor = appearance?.textColor
}
}
var isHiddenCursor: Bool = false
private var appearance: ItemAppearance?
init() {
super.init(frame: .zero)
clipsToBounds = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
guard let appearance = appearance else { return }
let length = min(appearance.itemSize.width, appearance.itemSize.height)
frame = CGRect(x: 0, y: 0, width: length, height: length)
layer.cornerRadius = length / 2
}
func set(appearance: ItemAppearance) {
self.appearance = appearance
bounds.size = appearance.itemSize
layer.borderColor = appearance.textColor.cgColor
layer.borderWidth = 1
layoutIfNeeded()
}
}