fix: sidebar avatar button color not update when toggle device appearance issue
This commit is contained in:
parent
0462ade3ae
commit
1cbc385253
|
@ -18,7 +18,7 @@ final class SidebarListContentView: UIView, UIContentView {
|
||||||
let avatarButton: CircleAvatarButton = {
|
let avatarButton: CircleAvatarButton = {
|
||||||
let button = CircleAvatarButton()
|
let button = CircleAvatarButton()
|
||||||
button.borderWidth = 2
|
button.borderWidth = 2
|
||||||
button.borderColor = UIColor.label.cgColor
|
button.borderColor = UIColor.label
|
||||||
return button
|
return button
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,18 @@ class AvatarButton: UIControl {
|
||||||
avatarImageView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
avatarImageView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func layoutSubviews() {
|
||||||
|
super.layoutSubviews()
|
||||||
|
|
||||||
|
updateAppearance()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||||
|
super.traitCollectionDidChange(previousTraitCollection)
|
||||||
|
|
||||||
|
updateAppearance()
|
||||||
|
}
|
||||||
|
|
||||||
func updateAppearance() {
|
func updateAppearance() {
|
||||||
avatarImageView.alpha = primaryActionState.contains(.highlighted) ? 0.6 : 1.0
|
avatarImageView.alpha = primaryActionState.contains(.highlighted) ? 0.6 : 1.0
|
||||||
|
|
|
@ -9,15 +9,18 @@ import UIKit
|
||||||
|
|
||||||
final class CircleAvatarButton: AvatarButton {
|
final class CircleAvatarButton: AvatarButton {
|
||||||
|
|
||||||
var borderColor: CGColor = UIColor.systemFill.cgColor
|
@Published var needsHighlighted = false
|
||||||
|
|
||||||
|
var borderColor: UIColor = UIColor.systemFill
|
||||||
var borderWidth: CGFloat = 1.0
|
var borderWidth: CGFloat = 1.0
|
||||||
|
|
||||||
override func layoutSubviews() {
|
override func updateAppearance() {
|
||||||
super.layoutSubviews()
|
super.updateAppearance()
|
||||||
|
|
||||||
layer.masksToBounds = true
|
layer.masksToBounds = true
|
||||||
layer.cornerRadius = frame.width * 0.5
|
layer.cornerRadius = frame.width * 0.5
|
||||||
layer.borderColor = borderColor
|
layer.borderColor = borderColor.cgColor
|
||||||
layer.borderWidth = borderWidth
|
layer.borderWidth = borderWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue