Last active
          September 28, 2021 15:33 
        
      - 
      
 - 
        
Save uy/3d9f4bd9c28063416f9da42425bb9430 to your computer and use it in GitHub Desktop.  
    Custom Checkbox iOS Swift
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import UIKit | |
| class CheckBox: UIButton { | |
| // Images | |
| let checkedImage = UIImage(named: "ic_check_box")! as UIImage | |
| let uncheckedImage = UIImage(named: "ic_check_box_outline_blank")! as UIImage | |
| // Bool property | |
| var isChecked: Bool = false { | |
| didSet{ | |
| if isChecked == true { | |
| self.setImage(checkedImage, forState: .Normal) | |
| } else { | |
| self.setImage(uncheckedImage, forState: .Normal) | |
| } | |
| } | |
| } | |
| override func awakeFromNib() { | |
| self.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside) | |
| self.isChecked = false | |
| } | |
| func buttonClicked(sender: UIButton) { | |
| if sender == self { | |
| isChecked = !isChecked | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
http://stackoverflow.com/questions/29117759/how-to-create-radio-buttons-and-checkbox-in-swift-ios
based on previous link