// // CheckBox.swift // GME Remit // // Created by InKwon James Kim on 2020/01/02. // Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved. // import UIKit import RxSwift import RxCocoa @objc protocol CheckBoxDelegate: class { func checkBox(_ checkBox: CheckBox, isSelected: Bool) } @IBDesignable public class CheckBox: UIView { private let xibName = "CheckBox" weak var delegate: CheckBoxDelegate? @IBOutlet private weak var checkMark: CheckMark! @IBOutlet private weak var button: UIButton! var isSelected: Bool = false { didSet { if isSelected { checkMark.animate(animationType: .check) } else { checkMark.animate(animationType: .remove) } delegate?.checkBox(self, isSelected: isSelected) } } @IBInspectable var borderWidth: CGFloat = 1 { didSet { update() } } @IBInspectable var borderColor: UIColor = .themeText { didSet { update() } } @IBInspectable var cornerRadius: CGFloat = 5 { didSet { update() } } override init(frame: CGRect) { super.init(frame: frame) commonInit() } required init?(coder: NSCoder) { super.init(coder: coder) commonInit() } override public func prepareForInterfaceBuilder() { update() } override public func awakeFromNib() { update() } private func commonInit() { guard let view = Bundle.main.loadNibNamed( xibName, owner: self, options: nil )?.first as? UIView else { return } view.frame = self.bounds view.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.addSubview(view) checkMark.strokeWidth = 2 update() } @IBAction private func touchCheck(_ sender: UIButton) { isSelected = !isSelected } private func update() { layer.cornerRadius = cornerRadius layer.borderWidth = borderWidth layer.borderColor = borderColor.cgColor } }