Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Sources/M13Checkbox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@

import UIKit

/// The delegate protocol fires when check and uncheck the box.
public protocol M13CheckboxDelegate: class {

/// Called when check the M13CheckBox
/// - Parameter checkBox: Current M13CheckBox object
func checked(_ checkBox:M13Checkbox)

/// Called when uncheck the M13CheckBox
/// - Parameter checkBox: Current M13Checkbox object
func unchecked(_ checkBox:M13Checkbox)
}

/// A customizable checkbox control for iOS.
@IBDesignable
open class M13Checkbox: UIControl {
Expand All @@ -21,6 +33,9 @@ open class M13Checkbox: UIControl {
// MARK: - Constants
//----------------------------

/// The M13Checkbox delegate.
weak public var delegate: M13CheckboxDelegate?

/**
The possible states the check can be in.

Expand Down Expand Up @@ -319,9 +334,11 @@ open class M13Checkbox: UIControl {
open func toggleCheckState(_ animated: Bool = false) {
switch checkState {
case .checked:
delegate?.unchecked(self)
setCheckState(.unchecked, animated: animated)
break
case .unchecked:
delegate?.checked(self)
setCheckState(.checked, animated: animated)
break
case .mixed:
Expand Down