2022-11-24 14:28:39 -05:00
|
|
|
//
|
|
|
|
// HUDButton.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by Jed Fox on 2022-11-24.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
2022-11-26 15:14:43 -05:00
|
|
|
public class HUDButton: UIView {
|
2022-11-24 14:28:39 -05:00
|
|
|
|
2022-11-26 15:14:43 -05:00
|
|
|
public static let height: CGFloat = 30
|
2022-11-24 14:28:39 -05:00
|
|
|
|
|
|
|
let background: UIVisualEffectView = {
|
|
|
|
let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemUltraThinMaterial))
|
|
|
|
backgroundView.alpha = 0.9
|
|
|
|
backgroundView.layer.masksToBounds = true
|
|
|
|
backgroundView.layer.cornerRadius = HUDButton.height * 0.5
|
|
|
|
return backgroundView
|
|
|
|
}()
|
|
|
|
|
|
|
|
let vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: UIBlurEffect(style: .systemUltraThinMaterial)))
|
|
|
|
|
2022-11-26 15:14:43 -05:00
|
|
|
public let button: UIButton = {
|
2022-11-24 14:28:39 -05:00
|
|
|
let button = HighlightDimmableButton()
|
|
|
|
button.expandEdgeInsets = UIEdgeInsets(top: -10, left: -10, bottom: -10, right: -10)
|
2022-11-26 09:39:24 -05:00
|
|
|
button.contentEdgeInsets = .constant(7)
|
2022-11-24 14:28:39 -05:00
|
|
|
button.imageView?.tintColor = .label
|
2022-11-26 09:39:24 -05:00
|
|
|
button.titleLabel?.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .bold))
|
2022-11-24 14:28:39 -05:00
|
|
|
return button
|
|
|
|
}()
|
|
|
|
|
2022-11-26 15:14:43 -05:00
|
|
|
public init(configure: (UIButton) -> Void) {
|
2022-11-24 14:28:39 -05:00
|
|
|
super.init(frame: .zero)
|
|
|
|
|
|
|
|
configure(button)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func _init() {
|
|
|
|
translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
background.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
addSubview(background)
|
|
|
|
background.pinToParent()
|
|
|
|
vibrancyView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
|
background.contentView.addSubview(vibrancyView)
|
|
|
|
|
|
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
vibrancyView.contentView.addSubview(button)
|
|
|
|
button.pinToParent()
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
heightAnchor.constraint(equalToConstant: HUDButton.height).priority(.defaultHigh),
|
|
|
|
])
|
|
|
|
}
|
2022-11-26 09:39:24 -05:00
|
|
|
|
2022-11-26 15:14:43 -05:00
|
|
|
public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
2022-11-26 09:39:24 -05:00
|
|
|
super.traitCollectionDidChange(previousTraitCollection)
|
|
|
|
button.titleLabel?.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .bold))
|
|
|
|
}
|
2022-11-26 14:29:30 -05:00
|
|
|
|
2022-11-26 15:14:43 -05:00
|
|
|
public override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
2022-11-26 14:29:30 -05:00
|
|
|
button.point(inside: button.convert(point, from: self), with: event)
|
|
|
|
}
|
|
|
|
|
2022-11-26 15:14:43 -05:00
|
|
|
public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
2022-11-26 14:29:30 -05:00
|
|
|
button
|
|
|
|
}
|
2022-11-24 14:28:39 -05:00
|
|
|
}
|