Nicer toolbar buttons

This commit is contained in:
James Magahern
2020-08-14 15:55:08 -07:00
parent 9b36a3ace5
commit 69029a3195
12 changed files with 534 additions and 187 deletions

View File

@@ -0,0 +1,57 @@
//
// SegmentedReliefButton.swift
// App
//
// Created by James Magahern on 8/14/20.
//
import UIKit
class SegmentedReliefButton: ReliefButton
{
var children: [ReliefButton] = [] {
willSet { children.forEach { $0.removeFromSuperview() } }
didSet { children.forEach { addSubview($0) }; setNeedsLayout() }
}
init(children: [ReliefButton]) {
super.init()
self.children = children
}
override var isHighlighted: Bool {
didSet {}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func sizeThatFits(_ size: CGSize) -> CGSize {
let width: CGFloat = children.reduce(0.0) { (result, button) -> CGFloat in
return result + button.sizeThatFits(size).width
}
return CGSize(width: width, height: size.height)
}
override func layoutSubviews() {
super.layoutSubviews()
backgroundView.frame = bounds
shadowView.frame = bounds
var buttonRect = CGRect(origin: .zero, size: CGSize(width: 0, height: bounds.height))
for child in children {
child.shadowView.isHidden = true
child.backgroundView.layer.borderWidth = 0
bringSubviewToFront(child)
let childSize = child.sizeThatFits(bounds.size)
buttonRect.size = CGSize(width: childSize.width, height: bounds.height)
child.frame = buttonRect
buttonRect.origin.x += buttonRect.width
}
}
}