gpt4 book ai didi

ios - 以编程方式添加的按钮在 ios 中不显示触摸感

转载 作者:搜寻专家 更新时间:2023-11-01 06:01:37 26 4
gpt4 key购买 nike

我在 IOS 应用程序的 UIView 中添加了 UIButton。它可以很好地处理目标操作,但是当我按下按钮时,它不会在屏幕上显示按下的感觉。 (当用户触摸普通按钮时,其标题会变暗)。

我使用了以下代码:

class CustomButton: UIButton {

override init(frame: CGRect) {
super.init(frame: frame)
setupViewLayouts()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupViewLayouts()
}

func setupViewLayouts() {

titleLabel?.font = UIFont.boldSystemFont(ofSize: 16.0)

backgroundColor = .black
layer.borderWidth = 1.0
layer.cornerRadius = 3.0
layer.borderColor = UIColor.clear.cgColor

setTitleColor(UIColor.black, for: .normal)
}
}

var btnLogin: CustomButton = {

let button = CustomButton()
button.setTitle("Login", for: .normal)
button.addTarget(self, action: #selector(btnLogin_Tapped), for: .touchUpInside)
return button
}()

addSubview(btnSignIn)

最佳答案

高亮效果仅在按钮样式为System时内置。您应该使用其他初始化程序,例如 CustomButton( style : .system )

关于ios - 以编程方式添加的按钮在 ios 中不显示触摸感,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48317211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com