あなたはこのような特定の状態のためにUIButtonの背景画像を設定することができます。ここでは
let image = UIImage.imageWithColor(someColor, size: CGSize(width: 1.0, height: 1.0))
btn.setBackgroundImage(image, for: .highlighted)
は(UIImageの拡張子の内側に置く)色から画像を作成するための機能である:
extension UIImage {
class func imageWithColor(_ color: UIColor, size: CGSize) -> UIImage {
let rect = CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
context!.setFillColor(color.cgColor)
context!.fill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
}
「ハイライトされた」状態の 'backgroundImage'も変更する必要があります。 – Sulthan