如何在 iOS 中添加不透明度?
How do I add opacity on touchdown in iOS?
我想在达阵事件中实现不透明。我附上了下面的代码。此代码正在为按钮的点击添加颜色。我如何确保只有不透明度起作用而不是颜色?
// Button touchdown event
@IBAction func touchdown(_ sender: UIButton) {
continueOutlet.setBackgroundColor(color: UIColor(named: "hover")!, forState: .highlighted)
}
更改所需颜色的 alpha 分量。
@IBAction func touchdown(_ sender: UIButton) {
continueOutlet.setBackgroundColor(color: continueOutlet.backgroundColor!.withAlphaComponent(0.5), forState: .highlighted)
}
您也可以仅在故事板中修改颜色的 alpha。
见附图
我想在达阵事件中实现不透明。我附上了下面的代码。此代码正在为按钮的点击添加颜色。我如何确保只有不透明度起作用而不是颜色?
// Button touchdown event
@IBAction func touchdown(_ sender: UIButton) {
continueOutlet.setBackgroundColor(color: UIColor(named: "hover")!, forState: .highlighted)
}
更改所需颜色的 alpha 分量。
@IBAction func touchdown(_ sender: UIButton) {
continueOutlet.setBackgroundColor(color: continueOutlet.backgroundColor!.withAlphaComponent(0.5), forState: .highlighted)
}
您也可以仅在故事板中修改颜色的 alpha。
见附图