How do I create a basic UIButton programmatically?

后端 未结 30 915
清歌不尽
清歌不尽 2020-11-22 14:41

How can I create a basic UIButton programmatically? For example in my view controller, when executing the viewDidLoad method, three UIButton<

30条回答
  •  情话喂你
    2020-11-22 15:27

    For Swift 2.0:

    let btnObject : UIButton  = UIButton() 
    btnObject.frame = CGRect(x: 8, y: 89, width: 70, height: 22)
    
    btnObject.titleLabel?.font = UIFont(name: "Helvetica Neue", size: 13)
    btnObject.titleLabel?.textColor = UIColor.whiteColor()
    btnObject.backgroundColor = UIColor(red: 189/255, green: 176/255, blue: 0/255, alpha: 1)
    btnObject.titleLabel?.textAlignment = NSTextAlignment.Center
    btnObject.addTarget(self, action: "btnbtnObjectClick:", forControlEvents: UIControlEvents.TouchUpInside)
    subView.addSubview(btnObject)
    

提交回复
热议问题