Class: ProMotion::XLFormColorSelectorCell

Inherits:
XLFormCell
  • Object
show all
Defined in:
lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb

Instance Method Summary collapse

Methods inherited from XLFormCell

#check_deprecated_styles, #value, #value=

Instance Method Details

#colorPickerDidChangeSelection(color_picker) ⇒ Object



80
81
82
83
84
# 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) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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(_) ⇒ Object



68
69
70
# 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) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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

#updateObject



72
73
74
75
76
77
78
# 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