Some appearance tweaks

This commit is contained in:
James Magahern
2021-06-14 16:32:51 -07:00
parent ecee3bd9bb
commit d959342180
5 changed files with 46 additions and 18 deletions

View File

@@ -11,12 +11,12 @@ class ReliefButton: UIButton
{
public var constrainedToSquare = true
internal var cornerRadius = CGFloat(8.0) { didSet { setNeedsLayout() } }
internal let shadowView = UIView(frame: .zero)
internal let backgroundView = GradientView(direction: .vertical, colors: ReliefButton.gradientColors(inverted: false, darkMode: false))
static let padding = CGFloat(24.0)
static let cornerRadius = CGFloat(6.0)
static let borderWidth = CGFloat(1.0)
static let borderWidth = CGFloat(1.0 / UIScreen.main.scale)
override var isHighlighted: Bool {
get {
@@ -53,14 +53,12 @@ class ReliefButton: UIButton
shadowView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
shadowView.layer.shadowRadius = 1.0
shadowView.layer.shadowOpacity = 1.0
shadowView.layer.cornerRadius = Self.cornerRadius
shadowView.layer.masksToBounds = false
shadowView.layer.shouldRasterize = true
shadowView.layer.rasterizationScale = UIScreen.main.scale
shadowView.layer.cornerCurve = .continuous
addSubview(shadowView)
backgroundView.layer.cornerRadius = Self.cornerRadius
backgroundView.isUserInteractionEnabled = false
backgroundView.layer.masksToBounds = true
backgroundView.layer.borderWidth = Self.borderWidth
@@ -85,7 +83,7 @@ class ReliefButton: UIButton
if darkMode {
if !inverted {
return [
UIColor(white: 0.30, alpha: 1.0),
UIColor(white: 0.20, alpha: 1.0),
UIColor(white: 0.10, alpha: 1.0)
]
} else {
@@ -159,7 +157,10 @@ class ReliefButton: UIButton
shadowView.frame = backgroundView.frame
let shadowPath = UIBezierPath(roundedRect: shadowView.bounds, cornerRadius: Self.cornerRadius)
let shadowPath = UIBezierPath(roundedRect: shadowView.bounds, cornerRadius: cornerRadius)
shadowView.layer.shadowPath = shadowPath.cgPath
backgroundView.layer.cornerRadius = cornerRadius
shadowView.layer.cornerRadius = cornerRadius
}
}

View File

@@ -27,7 +27,8 @@ class SegmentedReliefButton: ReliefButton
self.children = children
backgroundsContainerView.clipsToBounds = true
backgroundsContainerView.layer.cornerRadius = Self.cornerRadius - Self.borderWidth
backgroundsContainerView.layer.cornerRadius = self.cornerRadius + Self.borderWidth + 1.0
backgroundsContainerView.layer.cornerCurve = .continuous
constrainedToSquare = false
@@ -49,7 +50,7 @@ class SegmentedReliefButton: ReliefButton
return result + button.sizeThatFits(size).width
}
return CGSize(width: width, height: ourSize.height)
return CGSize(width: width + (2 * Self.borderWidth), height: ourSize.height)
}
override func setBackgroundInverted(_ inverted: Bool) {
@@ -66,18 +67,25 @@ class SegmentedReliefButton: ReliefButton
childrenHighlighObservations.removeAll()
backgroundsContainerView.subviews.forEach { $0.removeFromSuperview() }
let paddedSize = CGSize(
width: bounds.size.width - (Self.borderWidth * 2.0),
height: bounds.size.height - (Self.borderWidth * 2.0)
)
let darkMode = self.traitCollection.userInterfaceStyle == .dark
var buttonRect = CGRect(origin: .zero, size: CGSize(width: 0, height: bounds.height))
var buttonXOffset = CGFloat(Self.borderWidth)
for (i, child) in children.enumerated() {
child.shadowView.isHidden = true
child.backgroundView.isHidden = true
bringSubviewToFront(child)
let childSize = child.sizeThatFits(bounds.size)
buttonRect.size = CGSize(width: childSize.width, height: bounds.height)
child.frame = buttonRect
let childSize = child.sizeThatFits(paddedSize)
child.frame = CGRect(
origin: CGPoint(x: buttonXOffset, y: Self.borderWidth),
size: CGSize(width: childSize.width, height: paddedSize.height)
)
buttonRect.origin.x += buttonRect.width
buttonXOffset += child.frame.width
// Background
let backgroundView = GradientView(direction: .vertical, colors: Self.gradientColors(inverted: false, darkMode: darkMode))
@@ -92,7 +100,7 @@ class SegmentedReliefButton: ReliefButton
let separatorView = UIView(frame: CGRect(
x: child.frame.maxX,
y: 0,
width: 1.0,
width: 1.0 / UIScreen.main.scale,
height: bounds.height
))
separatorView.backgroundColor = .systemFill