1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| let btn:UIButton=UIButton.init(frame: CGRect.init(x: 100, y: 100, width: 100, height: 100)) btn.backgroundColor=UIColor.darkGray //设置背景图片 btn.setBackgroundImage(UIImage.init(named: "btn_01"), for: UIControl.State.normal) btn.setBackgroundImage(UIImage.init(named: "btn_02"), for: UIControl.State.highlighted) //设置按钮文字 btn.setTitle("点我啊", for: UIControl.State.normal) btn.setTitle("点我干啥", for: UIControl.State.highlighted) //设置文字颜色 btn.setTitleColor(UIColor.red, for: UIControl.State.normal) btn.setTitleColor(UIColor.blue, for: UIControl.State.highlighted) //设置对其方式 btn.contentVerticalAlignment=UIControl.ContentVerticalAlignment.bottom self.view.addSubview(btn);
|