Created
April 28, 2017 15:57
-
-
Save sam-moshenko/eecf146668a0e0eea4c192f31e7e3d7d to your computer and use it in GitHub Desktop.
BEMCheckBox "extension" to support some content view to be highlighted when the checkbox is checked
This file contains 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 | |
import BEMCheckBox | |
//BEMCheckBox does not have any text or image next to the checkbox itself | |
//This class helps a bit with that | |
@IBDesignable | |
class BEMCheckBoxWithView: BEMCheckBox { | |
//this is the view that stands near checkbox | |
//set tint color, it will be used when checkbox is selected | |
@IBOutlet weak var contentView: UIView! | |
//for this to work you need to add | |
//- (void)_setOn:(BOOL)on animated:(BOOL)animated notifyGroup:(BOOL)notifyGroup | |
//in BEMCheckBox.h class description (to make it public) | |
override func _set(on: Bool, animated: Bool, notifyGroup: Bool) { | |
super._set(on: on, animated: animated, notifyGroup: notifyGroup) | |
//set tint to the content view, whatever it is | |
if contentView is UIImageView { | |
let contentView = self.contentView as! UIImageView | |
contentView.image = contentView.image?.withRenderingMode(on ? .alwaysTemplate : .alwaysOriginal) | |
contentView.tintColorDidChange() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment