swift 學習小筆記之控件

1.UIButton

1> 增加addtarget事件

//不傳遞觸摸對象(即點擊的按鈕)
button.addTarget(self, action:#selector(tapped), for:.touchUpInside)
func tapped(){
     print("tapped")
}
 
//傳遞觸摸對象(即點擊的按鈕),需要在定義action參數時,方法名稱後面帶上冒號
button.addTarget(self, action:#selector(tapped(_:)), for:.touchUpInside)
 
func tapped(_ button:UIButton){
     print(button.title(for: .normal))
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章