forked from swifty-iOS/RadioCheckboxButton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckboxButtonContainerView.swift
60 lines (49 loc) · 1.96 KB
/
CheckboxButtonContainerView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// CheckboxButtonContainerView.swift
// RadioCheckboxButton
//
// Created by Manish Bhande on 14/01/18.
// Copyright © 2018 Manish. All rights reserved.
//
import UIKit
/// View container that hold all CheckboxButton available as first immediate subview only
open class CheckboxButtonContainerView: UIView {
private var _buttonContainer = CheckboxButtonContainer()
/// Access button container for more features
/// You can not change buttonContainer
public var buttonContainer: CheckboxButtonContainer {
return _buttonContainer
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// Load all Checkbox button
let buttons = subviews
for case let button as CheckboxButtonContainer.Kind in buttons {
addButton(button)
}
}
/// Ading subview in button conatiner if it is CheckboxButton
open override func didAddSubview(_ subview: UIView) {
super.didAddSubview(subview)
guard let button = subview as? CheckboxButtonContainer.Kind else { return }
addButton(button)
}
/// Removing CheckboxButton from container
open override func willRemoveSubview(_ subview: UIView) {
super.willRemoveSubview(subview)
guard let button = subview as? CheckboxButtonContainer.Kind else { return }
removeButton(button)
}
/// Add button in container even if it is not added as subview in container view
///
/// - Parameter button: CheckboxButtonContainer
public func addButton(_ button: CheckboxButtonContainer.Kind) {
buttonContainer.addButton(button)
}
/// Remove button from container. It will not remove from view. User removefromSuperview method delete button from view.
///
/// - Parameter button: CheckboxButtonContainer
public func removeButton(_ button: CheckboxButtonContainer.Kind) {
buttonContainer.removeButton(button)
}
}