Create a button programmatically and set a background image

前端 未结 11 1121
自闭症患者
自闭症患者 2020-12-07 17:44

When I try creating a button and setting a background image in Swift:

let button   = UIButton.buttonWithType(UIButtonType.System) as UIButton
    button.fram         


        
11条回答
  •  无人及你
    2020-12-07 18:12

    Swift: Ui Button create programmatically

    let myButton = UIButton()
    
    myButton.titleLabel!.frame = CGRectMake(15, 54, 300, 500)
    
    myButton.titleLabel!.text = "Button Label"
    
    myButton.titleLabel!.textColor = UIColor.redColor()
    
    myButton.titleLabel!.textAlignment = .Center
    
    myButton.addTarget(self,action:"Action:",forControlEvents:UIControlEvent.TouchUpInside)
    
    self.view.addSubview(myButton)
    

提交回复
热议问题