iOS-Swift-UIButton

//

//  ViewController.swift

//  Label

//

// Created by Zhao Shijun on 2019/11/18.

//  Copyright © 2019 赵士军. All rights reserved.

//

 

import UIKit

 

class ViewController: UIViewController {

 

    override func viewDidLoad() {

        super.viewDidLoad()

        // Button

        self .setupBtn()

        // Do any additional setup after loading the view.

    }

    

    func setupBtn() {

        // Initialize Btn

        let testBtn = UIButton.init(type: .custom)

        // set the position size

        testBtn.frame = CGRect(x: 10, y: 10, width: 200, height: 200)

      // set title

        testBtn .setTitle ( "Click me", for: .normal)

        // set the color

        testBtn .setTitleColor(.red, for: .normal)

    // set the font size

        testBtn.titleLabel?.font = .boldSystemFont(ofSize: 18)

        // add a click event 1

        testBtn .addTarget(self, action: #selector(testButtonClick), for: .touchUpInside)

        // Event 2

        testBtn .addTarget(self, action: #selector(buttonClick(_button:)), for: .touchUpInside)

        //mark

        testBtn.tag = 18

        // fillet

         testBtn.layer.cornerRadius = 100

        //

        testBtn.clipsToBounds = true

        //center

        testBtn.center = self.view.center

        

        testBtn.layer.borderWidth = 12

        testBtn.layer.borderColor = UIColor.red.cgColor

        testBtn.backgroundColor = .green

        self.view .addSubview(testBtn)

    

    }

    @objc testbutton click func () {

        

        print ( "click me")

    }

    @objc func buttonClick(_button:UIButton){

        

        print (String.init (format: "Click the% @ ---% d", _button, _button.tag))

    }

    /*

    // MARK: - Navigation

 

    // In a storyboard-based application, you will often want to do a little preparation before navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        // Get the new view controller using segue.destination.

        // Pass the selected object to the new view controller.

    }

    */

 

}

 

Guess you like

Origin www.cnblogs.com/ZsjXxy/p/11883312.html