Latest 2.1
Homepage https://github.com/kunass2/SelectableView
License MIT
Platforms ios 8.0
Authors

SelectableView

BSSelectableView
BSSelectableView
BSSelectableView
BSSelectableView
BSSelectableView
BSSelectableView

Installation

SelectableView is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "SelectableView"

If you used use_framework in your podfile just simply do:

import SelectableView

for every file when you need to use it.

you may also use:

@import SelectableView;

within bridging header file and avoid to import framework for every needed file.

Info

  • entirely written in latest Swift syntax.

Usage

Simply add SingleSelectableView, MultiSelectableView or SearchSelectableView as a subclass of your UIView in Interface Builder.

Connect following @IBOutlets:

@IBOutlet open var switchButton: UIButton?
@IBOutlet open var contentOptionsHeightConstraint: NSLayoutConstraint?
@IBOutlet open var contentOptionsView: UIView?
@IBOutlet open var selectedOptionLabel: UILabel? //only SingleSelectableView
@IBOutlet open var verticalTokenView: VerticalTokenView? //only MultiSelectableView
@IBOutlet open var horizontalTokenView: HorizontalTokenView?  //only MultiSelectableView
@IBOutlet open var tokenViewHeightConstraint: NSLayoutConstraint? //only MultiSelectableView, useful within UIScrollView
@IBOutlet open var textField: UITextField! //only SearchSelectableView

Assing delegates for your selectable views in viewDidLoad():

singleSelectableView.delegate = self
multiSelectableView.delegate = self
searchSelectableView.delegate = self

Conform your UIViewController to SelectableViewDelegate declared as following:

@objc public protocol SelectableViewDelegate {

    @objc optional func multiSelectableView(_ view: MultiSelectableView, tokenViewFor option: SelectableOption) -> UIView

    @objc optional func singleSelectableView(_ view: SingleSelectableView, didSelect option: SelectableOption)
    @objc optional func multiSelectableView(_ view: MultiSelectableView, didSelect option: SelectableOption)
    @objc optional func searchSelectableView(_ view: SearchSelectableView, didSelect option: SelectableOption)
    @objc optional func selectableViewDidToggleOptions(with button: UIButton, expanded: Bool)
}

Additionally in Interface Builder you may set up for every SelectableView the following properties:

    var fontForOption = UIFont.systemFont(ofSize: 16)
    var fontForPlaceholderText = UIFont.systemFont(ofSize: 14)

    @IBInspectable open var leftPaddingForPlaceholderText = 0
    @IBInspectable open var leftPaddingForOption = 20
    @IBInspectable open var heightForOption = 40

    @IBInspectable open var titleColorForSelectedOption = UIColor.green
    @IBInspectable open var titleColorForOption = UIColor.black
    @IBInspectable open var textColorForPlaceholderText = UIColor.gray
    @IBInspectable open var tintColorForSelectedOption = UIColor.blue

    @IBInspectable open var identifier = ""
    @IBInspectable open var tableViewAccessibilityIdentifier = ""
    @IBInspectable open var maxNumberOfRows = 6
    @IBInspectable open var placeholder = ""

If you need you are able to call public instance methods:

open func hideOptions() //collapse selectable options
open func select(option: SelectableOption) //only MultiSelectableView
open func deselect(option: SelectableOption) //only MultiSelectableView

You have access to the following properties:

open var options: [SelectableOption]? //current list of options able to select it
open var selectedOption: SelectableOption? //SingleSelectableView, SearchSelectableView
open var selectedOptions = [SelectableOption]() //MultiSelectableView

SelectableOption is defined as follows:

open class SelectableOption: NSObject {

    open var index: Int
    open var identifier: String
    open var title: String
    open var userInfo: [AnyHashable: Any]?

    open var descendantOptions = [SelectableOption]()

    public init(index: Int, title: String, identifier: String, userInfo: [AnyHashable: Any]? = nil) {

        self.index = index
        self.identifier = identifier
        self.title = title
        self.userInfo = userInfo
    }
}

Author

Bartłomiej Semańczyk, [email protected]

License

SelectableView is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "BSSelectableView",
    "version": "2.1",
    "summary": "Easily manage your token along with your single or multiply select view.",
    "description": "Looking for simple Swift library to manage multiply or single selection? This one is for you:)",
    "homepage": "https://github.com/kunass2/SelectableView",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Bartu0142omiej Semau0144czyk": "[email protected]"
    },
    "source": {
        "git": "https://github.com/kunass2/SelectableView.git",
        "tag": "2.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "SelectableView/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This