-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathUnderlineItemView.swift
More file actions
73 lines (53 loc) · 1.6 KB
/
UnderlineItemView.swift
File metadata and controls
73 lines (53 loc) · 1.6 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
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// UnderlineItemView.swift
// Demo
//
// Created by Jinsei Shima on 2018/11/17.
// Copyright © 2018 Jinsei Shima. All rights reserved.
//
import UIKit
import PinCodeInputView
final class UnderlineItemView: UIView, ItemType {
var isSecureText: Bool = false
var text: Character? = nil {
didSet {
guard let text = text else {
label.text = nil
return
}
label.text = String(text)
}
}
var isHiddenCursor: Bool = false
private let label: UILabel = .init()
private let underLineView: UIView = .init()
init() {
super.init(frame: .zero)
addSubview(label)
addSubview(underLineView)
clipsToBounds = true
label.textAlignment = .center
label.isUserInteractionEnabled = false
underLineView.backgroundColor = .lightText
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
label.frame = bounds
let width: CGFloat = bounds.width
let height: CGFloat = 2
underLineView.frame = CGRect(
x: (bounds.width - width) / 2,
y: (bounds.height - height),
width: width,
height: height
)
}
func set(appearance: ItemAppearance) {
label.font = appearance.font
label.textColor = appearance.textColor
layoutIfNeeded()
}
}