swift 点击button改变其内填充图片,达到选中的效果

先看下效果:

点击后:

     

实现:在页面拖一个button,然后在所在页面声明其变量和一个点击事件

 

声明:

@IBOutlet weak var BtnZiDong: UIButton!

点击事件函数:

 1 @IBAction func actionZiDong(sender: AnyObject) {
 2         BtnZiDong .setImage(UIImage(named: "check1.png"), forState:UIControlState.Normal)
 3         BtnZiDong .setImage(UIImage(named: "check.png"), forState: UIControlState.Selected)
 4         
 5         if BtnZiDong .selected == true{
 6             BtnZiDong .selected=false
 7         }else{
 8             BtnZiDong .selected = true
 9         }
10         
11         
12     }

 

posted on 2016-10-25 10:16  麦芽呀~  阅读(600)  评论(0编辑  收藏  举报