码迷,mamicode.com
首页 > 编程语言 > 详细

swift 简介和常量与变量 --- swift 入门

时间:2017-01-07 19:55:13      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:ble   add   ring   gre   技术分享   selector   str   rand   target   

一、思维导图技术分享

二、

技术分享代码

//创建UIView 和按钮     
let views = UIView(frame: CGRect(x:20, y: 20, width: 100, height: 100))//FIXME:改变viewsframe
        views.backgroundColor = UIColor.yellow
        view.addSubview(views)
        
        //MARK: 创建一个按钮
        let Button2 = UIButton(type: .contactAdd)
        Button2.backgroundColor = UIColor.red  //FIXME:sfsl
        Button2.frame = views.bounds
        views.addSubview(Button2)
        
        //        Button2 .addTarget(self, action: #selector(button2Click), for:)
        Button2.addTarget(self, action: #selector(button2Click), for: .touchUpInside)
    }
    //MARK:-- methods response
    func button2Click()  {
        print("按钮单击")
    }
//常量和变量
1
let a = 10 2 let b:Double = 105.3 3 // Binary operator ‘+‘ cannot be applied to operands of type ‘Int‘ and ‘Double‘ 4 print(a+Int(b)) 5 6 7 var name:String = "Hello Word" //不管是变量还是常量必须初始化,且常量的值不能改变 8 name = "我是 Hello Word" 9 print(name)
 //分支和三运算
 //1 if f
        let a = 10
        
        if a > 5 {
            print("a>5")
        }else{
            print("a<5")
        }
        //2 三目
        
//        a > 5 ? print("a大") : print("a小")
        //或写成
        a > 5 ? print("a大大大") :()

 

swift 简介和常量与变量 --- swift 入门

标签:ble   add   ring   gre   技术分享   selector   str   rand   target   

原文地址:http://www.cnblogs.com/TheYouth/p/6259951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!