CheckBox Demo

//  ViewController.swift
//  CheckBoxDemo


import UIKit

class ViewController: UIViewController {

    @IBOutlet var lbltitle: UILabel!
    
    @IBOutlet var lbl1: UILabel!
    
    @IBOutlet var lbl2: UILabel!
    
    @IBOutlet var lbl3: UILabel!
    
    @IBOutlet var check1: UIButton!
    
    @IBOutlet var check2: UIButton!
    
    @IBOutlet var check3: UIButton!
    
    
    @IBOutlet var lblTitle1: UILabel!
    
    @IBOutlet var radio1: UIButton!
    
    @IBOutlet var radio2: UIButton!
    
    @IBOutlet var lblRadio1: UILabel!
    
    @IBOutlet var lblRadio2: UILabel!
    
    
    
    var checkBox = UIImage(named: "check")
    var unCheckBox = UIImage(named: "uncheck")
    
    var isCheckClick = Bool()
    
    var radioBox = UIImage(named: "radioFill")
    var unRadioBox = UIImage(named: "radioBlank")
    
    var isRadioClick = Bool()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        isCheckClick = false
        isRadioClick = false
       radio1.setImage(radioBox, for: .normal)
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    @IBAction func tappedCheck1(_ sender: UIButton) {
        if isCheckClick == true
        {
           check1.setImage(checkBox, for: .normal)
            isCheckClick = false
        }
        else
        {   check1.setImage(unCheckBox, for: .normal)
            isCheckClick = true
        }
        
    }
    

       @IBAction func tappedCheck2(_ sender: UIButton) {
        if isCheckClick == true
        {
            check2.setImage(checkBox, for: .normal)
            isCheckClick = false
        }
        else
        {   check2.setImage(unCheckBox, for: .normal)
            isCheckClick = true
        }

    }

    @IBAction func tappedCheck3(_ sender: UIButton) {
        if isCheckClick == true
        {
            check3.setImage(checkBox, for: .normal)
            isCheckClick = false
        }
        else
        {   check3.setImage(unCheckBox, for: .normal)
            isCheckClick = true
        }

    }
    
    
    
    @IBAction func tappedRadio1(_ sender: UIButton) {
        
    
        
        if isRadioClick == true{
            radio1.setImage(radioBox, for: .normal)
            radio2.setImage(unRadioBox, for: .normal)
            isRadioClick = false
        }
        else
        {
              radio1.setImage(unRadioBox, for: .normal)
            radio2.setImage(radioBox, for: .normal)
            isRadioClick = true
        }
        
           }
    
    
    @IBAction func tappedRadio2(_ sender: UIButton) {
        if isRadioClick == true{
        radio2.setImage(radioBox, for: .normal)
        radio1.setImage(unRadioBox, for: .normal)
        isRadioClick = false
    }
    else
        {
        radio1.setImage(radioBox, for: .normal)
        radio2.setImage(unRadioBox, for: .normal)
        isRadioClick = true
        }
}

}

Comments