Skip to content

Commit 89d8cbf

Browse files
committed
Merge branches 'master' and 'master' of https://github.com/danceyoung/selectmultiplebuttons
2 parents ada29f4 + 5b4730e commit 89d8cbf

1 file changed

Lines changed: 80 additions & 2 deletions

File tree

README.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
1-
# selectmultiplebuttons
2-
A grouped buttons supporting multiple/radio selection and automatic layout.
1+
2+
3+
4+
> Written with [StackEdit](https://stackedit.io/).
5+
# SelectMultipleButtons
6+
A grouped buttons supporting multiple/radio selection and automatic layout by building with swift.
7+
## Demo (captured by GIPHY CAPTURE)
8+
![
9+
](https://github.com/danceyoung/selectmultiplebuttons/blob/master/demo/selectmultiplebuttons-demo.gif?raw=true)
10+
## Instruction
11+
You must adopt the `SelectMultipleButtonsDelegate` protocol. The protocol likes UITableViewDelegate and UITableDatasource, providing information that SelectMultipleButtons need to construct buttons and manage button selection...
12+
13+
_// how many buttons are returnd_
14+
15+
func numberOf(selectMultipleButtons: SelectMultipleButtons) -> Int
16+
17+
_// button returned that is at which index_
18+
19+
func buttonOf(selectMultipleButtons: SelectMultipleButtons, atIndex index: Int) -> UIButton
20+
21+
_//set maximumNumber selected_
22+
23+
_//default you can all select buttons_
24+
25+
_//if you set the value is 1, the selectmultiplebuttons will present radio selecting_
26+
27+
@objc optional func maximumNumberSelectedOf(selectMultipleButtons: SelectMultipleButtons) -> Int
28+
_//config, containnig the blow items_
29+
30+
_//edge's space (top, leading, bottom, trailling)_
31+
32+
_//between space (vertical space and horizontal space between buttons)_
33+
34+
func styleConfigOf(selectMultipleButtons: SelectMultipleButtons) -> StyleConfig
35+
_//button's singeltap event_
36+
37+
38+
@objc optional func didSingleTapOf(selectMultipleButtons: SelectMultipleButtons, atIndex index: Int) -> Void
39+
_//indexes selected and changed_
40+
41+
42+
@objc optional func indexesSelectedOf(selectMultipleButtons: SelectMultipleButtons, didChange indexes: [Int]) -> Void
43+
## code snap
44+
Init a selectMultipleButtons
45+
_//width is the maxwidth for SelectMultipleButtons view_
46+
47+
_//no care height, after performing SelectMultipleButtons.load(), the height is calced automaticly._
48+
49+
_// you must perform SelectMultipleButtons.load() befor adding it to parent view._
50+
51+
let selectMultipleButtons1 = SelectMultipleButtons.init(frame: CGRect.init(x: 0, y: tip1.frame.origin.y + tip1.frame.height, width: view.frame.width, height: 0))
52+
selectMultipleButtons1.delegate = **self**
53+
selectMultipleButtons1.load()
54+
view.addSubview(selectMultipleButtons1)
55+
56+
Conform required protocol
57+
58+
func numberOf(selectMultipleButtons: SelectMultipleButtons) -> Int {
59+
return buttonTitleArray1.count
60+
}
61+
62+
func buttonOf(selectMultipleButtons: SelectMultipleButtons, atIndex index: Int) -> UIButton {
63+
let button = UIButton.init()
64+
button.setTitle(buttonTitleArray1[index], for: .normal)
65+
//set none selected state
66+
button.setTitleColor(.lightGray, for: .normal)
67+
button.setBackgroundColor(.groupTableViewBackground, for: .normal)
68+
//set selected state
69+
button.setTitleColor(.white, for: .selected)
70+
button.setBackgroundColor(UIColor.init(red: 0x3B/0xFF, green: 0x67/0xFF, blue: 0xBC/0xFF, alpha: 1), for: .selected)
71+
//default button is selected
72+
button.isSelected = true
73+
return button
74+
}
75+
76+
func styleConfigOf(selectMultipleButtons: SelectMultipleButtons) -> StyleConfig {
77+
let edgeSpace = EdgeSpace.init(top: 10, leading: 10, bottom: 10, trailling: 10)
78+
let betweenSpace = BetweenSpace.init(horizontalSpace: 5, verticalSpace: 5)
79+
return StyleConfig.init(edgeSpace: edgeSpace, betweenSpace: betweenSpace, systemFontSize: 18)
80+
}

0 commit comments

Comments
 (0)