Skip to content

Latest commit

 

History

History
103 lines (74 loc) · 2.93 KB

README.md

File metadata and controls

103 lines (74 loc) · 2.93 KB

RadioColorPicker

CI Status Version License Platform SwiftPM


Example

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


Requirements

iOS 13.0+


Installation

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

pod 'RadioColorPicker'

Rx Extension

If you are using rxswift, you can use delegate as Observable with the code below.

import UIKit
import RadioColorPicker

import RxSwift
import RxCocoa

class RxRadioColorPickerDelegateProxy: DelegateProxy<RadioColorPicker, RadioColorPickerDelegate>, DelegateProxyType, RadioColorPickerDelegate {
  static func registerKnownImplementations() {
    self.register { radioColorPicker -> RxRadioColorPickerDelegateProxy in
      RxRadioColorPickerDelegateProxy(parentObject: radioColorPicker, delegateProxy: self)
    }
  }
  
  static func currentDelegate(for object: RadioColorPicker) -> RadioColorPickerDelegate? {
    return object.delegate
  }
  
  static func setCurrentDelegate(_ delegate: RadioColorPickerDelegate?, to object: RadioColorPicker) {
    object.delegate = delegate
  }
}

extension Reactive where Base: RadioColorPicker {
  var delegate: RxRadioColorPickerDelegateProxy {
    return RxRadioColorPickerDelegateProxy.proxy(for: self.base)
  }
  
  var selectedIndex: Observable<Int?> {
    return delegate.sentMessage(#selector(RadioColorPickerDelegate.didItemSelected(index:color:)))
      .map { value in
        if let selectedIndex = value.first as? Int {
          return selectedIndex
        }
        return nil
      }
  }
  
  var selectedColor: Observable<UIColor?> {
    return delegate.sentMessage(#selector(RadioColorPickerDelegate.didItemSelected(index:color:)))
      .map { value in
        if let selectedColor = value[1] as? UIColor {
          return selectedColor
        }
        return nil
      }
  }
}

Author

Wallaby, [email protected]


License

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