项目作者: VenkateshYadavP

项目描述 :
Radio Button and Radio Buttons View for iOS apps
高级语言: Swift
项目地址: git://github.com/VenkateshYadavP/PVRadioButton.git
创建时间: 2017-09-15T22:03:32Z
项目社区:https://github.com/VenkateshYadavP/PVRadioButton

开源协议:MIT License

下载


PVRadioButton

Radio Button and Radio Buttons View for iOS apps, Swift

This library allows you to easily add Radio Buttons to your views in two ways.

1) You can set PVRadioButton class as Custom class to your Buutton, then you can set title, color etc attributes to the button from Attributes Inspector and add those buttons to radio button group. you can have any number of groups.

2) You can just add a view and set its custom class as PVRadioButtonView, and pass array of button titles to it, it will create list of radio buttons with those titles and place in that view. you can either choose that list to be scrollable or non - scrollable from attribute inspector.

Preview

alt tag

Usage

You can use in two ways as I mentioned above.

First Drag and drop PVRadioButton folder into your app, then

1) for manually added buttons, You can set PVRadioButton Class as Custom class to your Button and add them to the group as below.

  1. var radioButtonGroup = PVRadioButtonGroup()
  2. radioButtonGroup.appendToRadioGroup(radioButtons: [button1,button2])
  3. radioButtonGroup.appendToRadioGroup(radioButtons: [button3,button4])

Here button1, button2 will be in one group and button3,button4 will be added to other group and ViewController has to implement RadioButtonGroupDelegate and set RadioButtonGroupDelegate to itself as below

  1. radioButtonGroup.delegate = self

and implement following method

  1. func radioButtonClicked(button: PVRadioButton) {
  2. print(button.titleLabel?.text ?? "")
  3. }

Here you will get button which is clicked.

2) You can just add a view and set its custom class to PVRadioButtonView and create outlet to it and pass array of string i.e. array of button titles as below

  1. @IBOutlet weak var radioView: PVRadioButtonView!
  2. radioView.addButtons(radioButtonTitles: ["India","Usa","China","Japan","Argentina","Armenia"])

and viewcontroller has to implement RadioButtonViewDelegate and set it to itself as below

  1. radioView.delegate = self

and implement following method

  1. func radioButtonClickedInView(button: PVRadioButton) {
  2. print(button.titleLabel?.text ?? "")
  3. }

Here you will get button which is clicked.

If you want it to be scrollable you can set buttonHeight and isScrollable to true from attributes inspector, if you set isScrollable to false it will adjust buttons height so that it all buttons fit in view.you can set various attributes from attributes inspector and change colors and heights according to your requirements.