Implemented find on page UI

This commit is contained in:
James Magahern
2020-09-30 18:06:47 -07:00
parent 1d27674d7d
commit 3769f5bbbf
12 changed files with 372 additions and 9 deletions

View File

@@ -0,0 +1,87 @@
//
// 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
label.font = UIFont.preferredFont(forTextStyle: .subheadline)
label.textAlignment = .center
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(
x: bounds.minX, y: 0.0,
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
}
}

View File

@@ -11,14 +11,20 @@ class DocumentControlViewController: UIViewController
{
let documentControlView = StackView(dimension: .vertical)
let fontSizeAdjustView = FontSizeAdjustView()
let findOnPageControlView = DocumentControlView()
static public let preferredWidth = CGFloat(200.0)
static public let controlHeight = CGFloat(48.0)
convenience init() {
self.init(nibName: nil, bundle: nil)
findOnPageControlView.label.text = "Find On Page"
findOnPageControlView.imageView.image = UIImage(systemName: "magnifyingglass")
fontSizeAdjustView.drawsBottomSeparator = true
documentControlView.addArrangedSubview(fontSizeAdjustView)
documentControlView.addArrangedSubview(findOnPageControlView)
}
override func loadView() {

View File

@@ -7,14 +7,14 @@
import UIKit
class FontSizeAdjustView: UIView
class FontSizeAdjustView: DocumentControlView
{
let decreaseSizeButton = UIButton(frame: .zero)
let increaseSizeButton = UIButton(frame: .zero)
let labelView = UILabel(frame: .zero)
convenience init() {
self.init(frame: .zero)
override init() {
super.init()
labelView.textColor = .secondaryLabel
labelView.textAlignment = .center
@@ -30,13 +30,15 @@ class FontSizeAdjustView: UIView
addSubview(labelView)
}
override func sizeThatFits(_ size: CGSize) -> CGSize {
CGSize(width: size.width, height: DocumentControlViewController.controlHeight)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
highlightView.isHidden = true
decreaseSizeButton.frame = CGRect(
x: 0.0, y: 0.0,
width: bounds.height,