【问题标题】:How do I change button text automatically with a segment change如何通过段更改自动更改按钮文本
【发布时间】:2018-02-04 02:51:38
【问题描述】:

我想为用户创建一个登录屏幕,所以当他们在分段控件的“登录”部分时,我希望它在我的按钮上显示“登录”。但是,当用户切换到“登录”部分时,我希望按钮显示“登录”而不是“登录”。到目前为止,我让它显示“登录”的唯一方法是让用户单击按钮,并使用 actionButton.setTitle("sign in", for: .normal) 更改文本,但我希望它在用户切换段时自动发生。有谁知道怎么做?

This is what my view controller for the sign up page looks like

【问题讨论】:

    标签: swift xcode uisegmentedcontrol


    【解决方案1】:
    override func viewDidLoad() {
        super.viewDidLoad()
        segment.addTarget(self, action: #selector(valueDidChange(segment:)), for: .valueChanged)
    }
    
    func valueDidChange(segment: UISegmentControl) {
        switch segment.selectedIndex {
        case 0:
            actionButton.setTitle("log in", for: .normal)
        default:
            actionButton.setTitle("sign in", for: .normal)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-31
      • 2021-11-16
      • 2016-12-11
      • 1970-01-01
      • 2013-05-21
      • 1970-01-01
      相关资源
      最近更新 更多