class ProMotion::XLFormColorSelectorCell

Public Instance Methods

colorPickerDidChangeSelection(color_picker) click to toggle source
# File lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb, line 80
def colorPickerDidChangeSelection(color_picker)
  color = color_picker.selectionColor
  @color_view.backgroundColor = color
  self.value = color
end
formDescriptorCellDidSelectedWithFormController(controller) click to toggle source
# File lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb, line 19
def formDescriptorCellDidSelectedWithFormController(controller)
  return if self.rowDescriptor.disabled

  self.formViewController.view.endEditing(true)

  size = if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
           [400, 440]
         else
           UIScreen.mainScreen.bounds.size
         end
  color_chooser = PMXLColorChooser.alloc.initWithFrame [[0, 0], size]
  color_chooser.delegate = self
  color_chooser.color = self.rowDescriptor.value || UIColor.whiteColor

  if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
    controller = UIViewController.new
    controller.view = color_chooser
    @popover = UIPopoverController.alloc.initWithContentViewController controller
    @popover.popoverContentSize = color_chooser.frame.size
    f = self.contentView.convertRect(@color_view.frame, toView: self.formViewController.view)
    @popover.presentPopoverFromRect(f,
                                    inView: self.formViewController.view,
                                    permittedArrowDirections: UIPopoverArrowDirectionAny,
                                    animated: true)
  else
    controller = UIViewController.new
    controller.view = color_chooser

    navigation_controller = UINavigationController.alloc.initWithRootViewController(controller)
    navigation_controller.navigationBar.translucent = false
    right = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemDone,
                                                              target: self,
                                                              action: 'hide_picker:')
    controller.navigationItem.rightBarButtonItem = right
    if self.formViewController.presentedViewController
      self.formViewController.dismissViewControllerAnimated(true,
                                                            completion: -> {
                                                              self.formViewController.presentViewController(navigation_controller,
                                                                                                            animated: true,
                                                                                                            completion: nil)
                                                            })
    else
      self.formViewController.presentViewController(navigation_controller,
                                                    animated: true,
                                                    completion: nil)
    end
  end
end
hide_picker(_) click to toggle source
# File lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb, line 68
def hide_picker(_)
  self.formViewController.dismissViewControllerAnimated(true, completion: nil)
end
setup(data_cell, screen) click to toggle source
Calls superclass method
# File lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb, line 4
def setup(data_cell, screen)
  super
 
  @color_view = UIView.alloc.initWithFrame [[0, 0], [80, 30]]
  @color_view.contentMode = UIViewContentModeScaleAspectFit
  @color_view.layer.borderWidth = 1
  @color_view.layer.borderColor = UIColor.blackColor.CGColor
  @color_view.backgroundColor = UIColor.whiteColor
  self.accessoryView = @color_view

  self.selectionStyle = UITableViewCellSelectionStyleNone
  self.backgroundColor = UIColor.whiteColor
  self.separatorInset = UIEdgeInsetsZero
end
update() click to toggle source
# File lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb, line 72
def update
  color = value
  unless color
    color = UIColor.whiteColor
  end
  @color_view.backgroundColor = color
end