Latest 1.1.0
Homepage https://github.com/luosai001/OptionControl
License MIT
Platforms ios 8.0
Frameworks UIKit
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

OptionControl 实现多选,单选功能,纯swift编写

import UIKit
import OptionControl
class ViewController: UIViewController,SelectionControlDelegate,SelectionControlDataSource {

var optionView :SelectionControl?
var titles :Array<String>?
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    //         self.singleSelection()
    self.mutilSelection()
    //        self.datasourceDemo()

}

// delegate - SelectionControlDataSource
func titlesForSeletionOptionItems(selectionControl: SelectionControl) -> Array<String> {
    return ["赞成","反对","弃权"]
}

func unseletedImageAndSeletedImage(selectionControl: SelectionControl) -> (unseletedImage: String, seletedImage: String) {
    return ("zf_unselect","zf_select")
}

func selectedIndexs(selectionControl: SelectionControl) -> Array<Int> {
    return [0]
}

func selectedOptionType() -> SelectionType {
    return .MutilSelectionType
}

func backgroundColorForSeletionOptionItems() -> UIColor {
    return UIColor.lightGrayColor()
}

//Demo
func datasourceDemo(){
    optionView = SelectionControl()
    optionView!.delegate = self
    optionView!.dataSource = self
    optionView!.translatesAutoresizingMaskIntoConstraints = false ;
    self.view .addSubview(optionView!);
}

func singleSelection(){
    titles = ["赞成","反对","弃权"]

    optionView = SelectionControl(titles: titles!,selectedIndexs: [0],selectionType: SelectionType.SingleSelectionType,unselectedImage: "zf_unselect",selectedImage: "zf_select",backgroundColorForSeletionOptionItems: UIColor.lightGrayColor())
    optionView!.delegate = self
    optionView!.translatesAutoresizingMaskIntoConstraints = false ;
    self.view .addSubview(optionView!);
}

func mutilSelection(){

    titles = ["赞成","反对","弃权"]

    optionView = SelectionControl(titles: titles!,selectedIndexs: [0],selectionType: SelectionType.MutilSelectionType,unselectedImage: "zf_unselect",selectedImage: "zf_select",backgroundColorForSeletionOptionItems: UIColor.lightGrayColor())
    optionView!.delegate = self
    optionView!.translatesAutoresizingMaskIntoConstraints = false ;
    self.view .addSubview(optionView!);

}

// delegate - SelectionControlDelegate
func selectionControl(selectionControl: SelectionControl, didSelectedOptions selecedIndexs: Array<Int>?) {
    print("(selecedIndexs)")
}
// layout
override func viewWillLayoutSubviews() {
    optionView!.removeConstraints(optionView!.constraints)
    let constHL = NSLayoutConstraint(item: optionView!, attribute: .Leading, relatedBy: .Equal, toItem: self.view, attribute: .Leading, multiplier: 1, constant: 0)
    let constVT = NSLayoutConstraint(item: optionView!, attribute: .Top, relatedBy: .Equal, toItem: self.view, attribute: .Top, multiplier: 1, constant: 0)

    let constW = NSLayoutConstraint(item: optionView!, attribute: .Width, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: .Width, multiplier: 1, constant: 0)
    let constH = NSLayoutConstraint(item: optionView!, attribute: .Height , relatedBy: .Equal, toItem: self.view, attribute: .Height, multiplier: 1, constant: 0)

    self.view .addConstraints([constH,constHL,constVT,constW])

}

}

Requirements

Installation

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

pod "OptionControl"

Author

luosai, [email protected]

License

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

Latest podspec

{
    "name": "OptionControl",
    "version": "1.1.0",
    "summary": "OptionControl for SingleOption and MutilOption",
    "description": "OptionControl for SingleOption and MutilOption that helps you",
    "homepage": "https://github.com/luosai001/OptionControl",
    "license": "MIT",
    "authors": {
        "luosai": "[email protected]"
    },
    "source": {
        "git": "https://github.com/luosai001/OptionControl.git",
        "tag": "1.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "OptionControl/Classes/**/*",
    "resource_bundles": {
        "OptionControl": [
            "OptionControl/Assets/*.png"
        ]
    },
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This