首页 > 移动平台 > 详细

IOS开发系列之Swift_UI_Btn

时间:2016-03-15 12:13:45      阅读:186      评论:0      收藏:0      [点我收藏+]

import UIKit

 

class ViewController: UIViewController {

 

    //声明一个btn

    var exampleBtn : UIButton!

    

    override func viewDidLoad() {

        super.viewDidLoad()

        //声明一个方法

        makeBtn()

        // Do any additional setup after loading the view, typically from a nib.

    }

 

    //方法

    private func makeBtn() {

        //初始化

        self.exampleBtn = UIButton.init()

        //设置frame

        self.exampleBtn.frame = CGRectMake(100, 100, 60, 60)

        //设置背景颜色

        //self.exampleBtn.backgroundColor = UIColor.lightGrayColor()

        //设置btn 字体大小

        self.exampleBtn.titleLabel?.font = UIFont.systemFontOfSize(12)

        //设置btn 的文字

        self.exampleBtn.setTitle("clickBnt", forState: UIControlState.Normal)

        //标记tag

        self.exampleBtn.tag = 520

        //添加点击事件

        self.exampleBtn.addTarget(self, action: "clickBtnDown:", forControlEvents: UIControlEvents.TouchUpInside)

        //设置btn的图片

        self.exampleBtn.setImage(UIImage(imageLiteral: "103"), forState: UIControlState.Normal)

        self.view .addSubview(self.exampleBtn)

    }

    

    //btn 的点击事件

    func clickBtnDown(btn : UIButton) {

        print("\(btn.tag)")

    }

    

    

    

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

 

 

}

IOS开发系列之Swift_UI_Btn

原文:http://www.cnblogs.com/godlovexq/p/5278790.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!