zoukankan      html  css  js  c++  java
  • IOS开发系列之Swift_UI_Btn

    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.

        }

    }

  • 相关阅读:
    svn使用教程
    事务的隔离级别--全网最详细
    idea的java类图标C不见,取而代之是J标识,且写代码无提示
    text .global_start 和_start
    transformClassesWithDexForDebug
    RxJava基本流程和lift源码分析
    Rxlifecycle(三):坑
    Rxlifecycle(二):源码解析
    RxJava操作符之Share, Publish, Refcount
    Rxlifecycle(一):使用
  • 原文地址:https://www.cnblogs.com/godlovexq/p/5278790.html
Copyright © 2011-2022 走看看