你可以使用
let textColor = button.titleLabel?.textColor
文字的颜色,并将其分配给您的BORDERCOLOR这样的:
button.layer.borderColor = textColor!.CGColor
顺便说一下,从我的测试中,蓝色是#007aff
你可以初始化它使用:
let color = UIColor(red: 0, green: 0.478, blue: 1, alpha: 1)
更新
class MyButton: UIButton {
private let normalColor = UIColor(red: 0, green: 0.478, blue: 1, alpha: 1)
private let highlightedColor = UIColor(red: 0, green: 0.478, blue: 1, alpha: 0.3)
override var highlighted: Bool {
willSet {
if newValue != highlighted {
let anim = CABasicAnimation(keyPath: "borderColor")
anim.fromValue = newValue ? normalColor.CGColor : highlightedColor.CGColor
anim.toValue = newValue ? highlightedColor.CGColor : normalColor.CGColor
layer.borderColor = newValue ? highlightedColor.CGColor : normalColor.CGColor
anim.duration = CATransaction.animationDuration()
anim.timingFunction = CATransaction.animationTimingFunction()
layer.addAnimation(anim, forKey: "MyButton.BorderColor")
}
}
}
}