项目作者: sekies

项目描述 :
Simple RadioButton for iOS
高级语言: Swift
项目地址: git://github.com/sekies/YSRadioButton.git
创建时间: 2019-09-04T06:04:06Z
项目社区:https://github.com/sekies/YSRadioButton

开源协议:MIT License

下载


YSRadioButton

YSRadioButtonは簡単に使えるiOS用のswift製ラジオボタンライブラリです。

radioButton 
radioButton2 
radioButton2 

Features

ブラウザ標準のようなラジオボタンです。

Installation

CocoaPods

  1. Podfileに pod 'YSRadioButton', :git => 'https://github.com/sekies/YSRadioButton.git' と追加します。
  2. pod install します。

Usage

  1. YSRadioButtonをインポートします。
    1. import YSRadioButton
  2. 任意のUIViewContorollerでYSRadioButtonViewControllerDelegate プロトコルに準拠します。
    1. class ViewController: UIViewController,YSRadioButtonViewControllerDelegate {
  3. YSRadioButtonViewControllerインスタンスを生成します。生成時にラジオボタンのラベルを配列で指定します。
    1. let radio = YSRadioButtonViewController(labels: ["Orange","GrapeFruits","Banana"])
  4. delegateと各種デザインプロパティを設定します。必須となるのはdelegateのみです。
    1. radio.delegate = self
    2. radio.font = UIFont.systemFont(ofSize: 18)
    3. radio.labelColor = .black
    4. radio.labelMargin = 0
    5. radio.lineWidth = 1
    6. radio.radioHeadFillSize = 0.6
    7. radio.radioHeadMargin = 5
    8. radio.radioHeadStroke = .darkGray
    9. radio.radioHeadFill = .red
  5. 親UIViewControllerに生成したYSRadioButtonViewControllerをaddChildしコンテナとなるUIViewにYSRadioButtonViewControllerのviewをaddSubviewします。ラジオボタンの位置はコンテナとなるUIViewに依存します。
    1. addChild(radio)
    2. radio.view.frame = container.bounds
    3. container.addSubview(radio.view)
    4. radio.didMove(toParent: self)
  6. デリゲートメソッドを実装します。ラジオボタンを選択するとこのメソッドが呼ばれます。YSRadioButtonViewController生成時に追加した配列の順にIntが割り振られます。
    1. func didYSRadioButtonSelect(no: Int) {
    2. print(no)
    3. }