Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
/ BGStatePicker Public archive

BGStatePicker is an iOS UIControl which lets pick states !

License

Notifications You must be signed in to change notification settings

grimabe/BGStatePicker

Repository files navigation

Build Status Build Status Carthage compatible License

BGStatePicker

BGStatePicker is a component that allows showing different states and selecting one.

BGStatePicker demo

Usage

BGStatePicker implement is a UIControl that receive a datasource to show different states.

Example code

import BGStatePicker

//....

let openState = BGStateable()
openState.stateText = "Open"
openState.stateBackgroundColor = .greenColor()

let closedState = BGStateable()
closedState.stateText = "Close"
closedState.stateBackgroundColor = .redColor()

let statusStates = [openState, closedState]

statePickerView.datasource = self
statePickerView.reloadData()

Datasource

extension ViewController: BGStatePickerDatasource {

	func numberOfState(statePickerView: BGStatePickerView) -> Int {
			return statusStates.count
	}
	func stateForIndex(statePickerView: BGStatePickerView, index: Int) -> BGStateable {
			return statusStates[index]
		}
	}
}

Get notified when the user pick a state

BGStatePicker inherits from UIControl and implements the .ValueChanged event.

//in viewDidLoad{
  //....

  statePickerView.addTarget(self, action: #selector(pickState(_:)), forControlEvents: [.ValueChanged])

  //...
}
...

func pickState(sender: BGStatePickerView) {
  if let state = sender.selectedValue { // BGStateable
    print("You pick state \(state.stateText)")
  }
}

Installation

Carthage

github "grimabe/BGStatePicker" ~> 0.2.0

CocoaPods

pod "BGStatePicker", "~> 0.2.0"

Requirements

BGStatePicker requires iOS 8 or later.

Author

Benjamin Grima

License

BGStatePicker is licensed under the MIT License.

About

BGStatePicker is an iOS UIControl which lets pick states !

Resources

License

Stars

Watchers

Forks

Packages

No packages published