Make a UIButton programmatically in Swift

后端 未结 19 1794
死守一世寂寞
死守一世寂寞 2020-11-27 10:00

I am trying to build UI\'s programmatically. How do I get this action working? I am developing with Swift.

Code in viewDidLoad:

over         


        
19条回答
  •  难免孤独
    2020-11-27 10:44

    Swift 4.2 - XCode 10.1

    Using a closure

    let button: UIButton = {
      let button = UIButton(type: .system)
      button.titleLabel?.font = UIFont.systemFont(ofSize: 20)
      ...
      return button
    }()
    

提交回复
热议问题