標籤: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 = 102 let b:Double = 105.33 // 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 入門