Create a button programmatically and set a background image

前端 未结 11 1120
自闭症患者
自闭症患者 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 17:57

    This is how you can create a beautiful button with a bezel and rounded edges:

    loginButton = UIButton(frame: CGRectMake(self.view.bounds.origin.x + (self.view.bounds.width * 0.325), self.view.bounds.origin.y + (self.view.bounds.height * 0.8), self.view.bounds.origin.x + (self.view.bounds.width * 0.35), self.view.bounds.origin.y + (self.view.bounds.height * 0.05)))
    loginButton.layer.cornerRadius = 18.0
    loginButton.layer.borderWidth = 2.0
    loginButton.backgroundColor = UIColor.whiteColor()
    loginButton.layer.borderColor = UIColor.whiteColor().CGColor
    loginButton.setTitle("Login", forState: UIControlState.Normal)
    loginButton.setTitleColor(UIColor(red: 24.0/100, green: 116.0/255, blue: 205.0/205, alpha: 1.0), forState: UIControlState.Normal)
    

提交回复
热议问题