淘先锋技术网

首页 1 2 3 4 5 6 7

iOS[Swift]中UIButton的使用

//
//  ViewController.swift
//  ShopCart
//
//  Created by BO on 17/2/16.
//  Copyright © 2017年 xsqBo. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let button = UIButton(type:UIButtonType.custom)
        button.frame = CGRect(x:,y:,width:,height:)
        button.backgroundColor = UIColor.black
        button.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)

        button.setTitle("测试啦", for: .normal)//可省略UIControlState

        button.setTitleColor(UIColor.red, for: UIControlState.normal)
        //文字图标的设置
        button.setImage(UIImage.init(named: "54056be791853"), for: UIControlState.normal)
//        button.setBackgroundImage(UIImage.init(named: ""), for: .normal)
        self.view.addSubview(button)

        // Do any additional setup after loading the view, typically from a nib.
    }
    func buttonClick(button:UIButton) {
        print("按钮点击了\(button.titleLabel?.text)")
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}