Git Product home page Git Product logo

selectmultiplebuttons's Introduction

Written with StackEdit.

SelectMultipleButtons

A grouped buttons supporting multiple/radio selection and automatic layout by building with swift. https://github.com/danceyoung/react-native-selectmultiple-button for React Native.

Demo (captured by GIPHY CAPTURE)

Installation

Edit your podfile

pod 'selectmultiplebuttons', '~> 0.0.4'

View frames hierarchy

enter image description here

Instruction

You must adopt the SelectMultipleButtonsDelegate protocol. The protocol likes UITableViewDelegate and UITableDatasource, providing information that SelectMultipleButtons need to construct buttons and manage button selection...

// how many buttons are returned

func numberOf(selectMultipleButtons: SelectMultipleButtons) -> Int

// button returned that is at which index

func buttonOf(selectMultipleButtons: SelectMultipleButtons, atIndex index: Int) -> UIButton

//set maximumNumber selected

//default you can select all buttons

//if you set the value is 1, the selectmultiplebuttons will present radio selecting

@objc optional func maximumNumberSelectedOf(selectMultipleButtons: SelectMultipleButtons) -> Int

//config, containnig the blow items

//edge's space (top, leading, bottom, trailling)

//between space (vertical space and horizontal space between buttons)

func styleConfigOf(selectMultipleButtons: SelectMultipleButtons) -> StyleConfig

//button's singeltap event

@objc optional func didSingleTapOf(selectMultipleButtons: SelectMultipleButtons, atIndex index: Int) -> Void

//indexes selected and changed event

@objc optional func indexesSelectedOf(selectMultipleButtons: SelectMultipleButtons, didChange indexes: [Int]) -> Void

code snap

Import modules

import selectmultiplebuttons

Init a selectMultipleButtons

//width is the maxwidth for SelectMultipleButtons view

//no care height, after performing SelectMultipleButtons.load(), the height is calced automaticly.

// you must perform SelectMultipleButtons.load() befor adding it to parent view.

let selectMultipleButtons1 = SelectMultipleButtons.init(frame: CGRect.init(x: 0, y: tip1.frame.origin.y + tip1.frame.height, width: view.frame.width, height: 0))
selectMultipleButtons1.delegate = self
selectMultipleButtons1.load()
view.addSubview(selectMultipleButtons1)

Conform required protocol

func numberOf(selectMultipleButtons: SelectMultipleButtons) -> Int {
    return  buttonTitleArray1.count
}

func buttonOf(selectMultipleButtons: SelectMultipleButtons, atIndex index: Int) -> UIButton {
    let button = UIButton.init()
    button.setTitle(buttonTitleArray1[index], for: .normal)
    //set none selected state
    button.setTitleColor(.lightGray, for: .normal)
    button.setBackgroundColor(.groupTableViewBackground, for: .normal)
    //set selected state
    button.setTitleColor(.white, for: .selected)
    button.setBackgroundColor(UIColor.init(red: 0x3B/0xFF, green: 0x67/0xFF, blue: 0xBC/0xFF, alpha: 1), for: .selected)
    //default button is selected
    button.isSelected = true
    return button
}

func styleConfigOf(selectMultipleButtons: SelectMultipleButtons) -> StyleConfig {
    let edgeSpace = EdgeSpace.init(top: 10, leading: 10, bottom: 10, trailling: 10)
    let betweenSpace = BetweenSpace.init(horizontalSpace: 5, verticalSpace: 5)
    return StyleConfig.init(edgeSpace: edgeSpace, betweenSpace: betweenSpace, systemFontSize: 18)
}

License

selectmultiplebuttons is MIT licensed.

selectmultiplebuttons's People

Contributors

danceyoung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

carabina bho9668

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.