Posts

Create UIButton programmatically with swift 4.1

Image
Code for creating  UIButton programmatically with swift 4.1 is as below : class ViewController: UIViewController  {     override func viewDidLoad()     {         super.viewDidLoad()                  let button = UIButton();         button.setTitle("Add", for: .normal)//text on button         button. showsTouchWhenHighlighted = true//when touched shows the highlight         button.setTitleColor(.blue, for: UIControlState.normal)//set font color         button.frame = CGRect(x: 0, y: 50, width: 200, height: 100)         button.backgroundColor = .cyan         button.layer.borderWidth=1.0         button.layer.borderColor = UIColor.black.cgColor         button.layer.cornerRadius = 15.0      ...