Make a UIButton programmatically in Swift

后端 未结 19 1849
死守一世寂寞
死守一世寂寞 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:42

    For Swift 3 Xcode 8.......

    let button = UIButton(frame: CGRect(x: 0, y: 0, width: container.width, height: container.height))
            button.addTarget(self, action: #selector(self.barItemTapped), for: .touchUpInside)
    
    
    func barItemTapped(sender : UIButton) {
        //Write button action here
    }
    

提交回复
热议问题