2020-09-30 18:06:47 -07:00
|
|
|
//
|
|
|
|
|
// DocumentControlView.swift
|
|
|
|
|
// App
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 9/30/20.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
|
|
class DocumentControlView: UIControl
|
|
|
|
|
{
|
|
|
|
|
static public let controlHeight = CGFloat(48.0)
|
|
|
|
|
|
|
|
|
|
let imageView = UIImageView(frame: .zero)
|
|
|
|
|
let label = UILabel(frame: .zero)
|
|
|
|
|
|
|
|
|
|
var drawsBottomSeparator: Bool = false {
|
|
|
|
|
didSet { setNeedsLayout() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal let highlightView = UIView(frame: .zero)
|
|
|
|
|
internal let separatorView = UIView(frame: .zero)
|
|
|
|
|
|
|
|
|
|
init() {
|
|
|
|
|
super.init(frame: .zero)
|
|
|
|
|
|
|
|
|
|
addSubview(highlightView)
|
|
|
|
|
addSubview(imageView)
|
|
|
|
|
addSubview(label)
|
|
|
|
|
addSubview(separatorView)
|
|
|
|
|
|
|
|
|
|
tintColor = .label
|
|
|
|
|
|
2021-02-11 12:26:13 -08:00
|
|
|
label.font = UIFont.preferredFont(forTextStyle: .body)
|
|
|
|
|
label.textAlignment = .left
|
2020-09-30 18:06:47 -07:00
|
|
|
|
|
|
|
|
imageView.contentMode = .center
|
|
|
|
|
|
|
|
|
|
separatorView.backgroundColor = .secondarySystemFill
|
|
|
|
|
highlightView.backgroundColor = .secondarySystemFill
|
|
|
|
|
|
|
|
|
|
highlightView.isHidden = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func sizeThatFits(_ size: CGSize) -> CGSize {
|
|
|
|
|
CGSize(width: size.width, height: Self.controlHeight)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func layoutSubviews() {
|
|
|
|
|
super.layoutSubviews()
|
|
|
|
|
|
|
|
|
|
highlightView.frame = bounds
|
|
|
|
|
|
|
|
|
|
let padding: CGFloat = 18.0
|
|
|
|
|
let imageSize: CGFloat = 24.0
|
|
|
|
|
let bounds = self.bounds.inset(by: layoutMargins)
|
|
|
|
|
imageView.frame = CGRect(
|
2021-02-15 22:47:02 -08:00
|
|
|
x: bounds.minX + 6.0, y: 0.0,
|
2020-09-30 18:06:47 -07:00
|
|
|
width: imageSize, height: imageSize
|
|
|
|
|
).centeredY(inRect: self.bounds)
|
|
|
|
|
|
|
|
|
|
label.frame = CGRect(
|
|
|
|
|
x: imageView.frame.maxX + padding, y: bounds.minY,
|
|
|
|
|
width: bounds.width - imageView.frame.maxX - padding, height: bounds.height
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let separatorHeight: CGFloat = 1.0
|
|
|
|
|
if drawsBottomSeparator {
|
|
|
|
|
separatorView.isHidden = false
|
|
|
|
|
separatorView.frame = CGRect(
|
|
|
|
|
x: self.bounds.minX, y: self.bounds.height - separatorHeight,
|
|
|
|
|
width: self.bounds.width, height: separatorHeight
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
separatorView.isHidden = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func setTracking(_ tracking: Bool) {
|
|
|
|
|
super.setTracking(tracking)
|
|
|
|
|
highlightView.isHidden = !tracking
|
|
|
|
|
}
|
|
|
|
|
}
|