【发布时间】:2020-09-30 04:52:08
【问题描述】:
我编写了一个代码来创建一个应该更改标签/文本字段的值的按钮。 我想制作一个俯卧撑应用程序,每次触摸屏幕上的按钮时,标签“您的分数:0”都会将分数增加 1,我也尝试将其作为文本字段。但它不起作用,什么都没有发生! 有人可以帮我吗?
标签代码:
func setupHelloWorld() {
helloworld.textAlignment = .center
helloworld.text = "Your Score: \(score)"
helloworld.textColor = .gray
helloworld.font = .boldSystemFont(ofSize: 30)
self.view.addSubview(helloworld)
...
按钮代码:
func setUpNetButton() {
nextButton.backgroundColor = .blue
nextButton.setTitleColor(.white, for: .normal)
nextButton.setTitle("Tap!", for: .normal)
nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside)
view.addSubview(nextButton)
setUpNextButtonConstraints()
}
@objc func nextButtonTapped() {
score += 1
}
【问题讨论】:
标签: swift button uibutton uitextfield uilabel