Class: XLFormColorSelectorCell
- Inherits:
-
XLFormBaseCell
- Object
- XLFormBaseCell
- XLFormColorSelectorCell
- Defined in:
- lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb
Instance Method Summary collapse
- #colorPickerDidChangeSelection(color_picker) ⇒ Object
- #configure ⇒ Object
- #hide_picker(_) ⇒ Object
- #on_color_tap(_) ⇒ Object
- #update ⇒ Object
Instance Method Details
#colorPickerDidChangeSelection(color_picker) ⇒ Object
84 85 86 87 88 |
# File 'lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb', line 84 def colorPickerDidChangeSelection(color_picker) color = color_picker.selectionColor @color_view.backgroundColor = color self.rowDescriptor.value = color end |
#configure ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb', line 2 def configure super.tap do self.selectionStyle = UITableViewCellSelectionStyleNone @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 tap = UITapGestureRecognizer.alloc.initWithTarget(self, action: 'on_color_tap:') self.addGestureRecognizer(tap) self.accessoryView = @color_view end end |
#hide_picker(_) ⇒ Object
66 67 68 |
# File 'lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb', line 66 def hide_picker(_) self.formViewController.dismissViewControllerAnimated(true, completion: nil) end |
#on_color_tap(_) ⇒ Object
17 18 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 |
# File 'lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb', line 17 def on_color_tap(_) unless self.rowDescriptor.disabled self.formViewController.view.endEditing(true) size = if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad [400, 440] else [320, 440] 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 = UINavigationController.alloc.initWithRootViewController(controller) ..translucent = false right = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemDone, target: self, action: 'hide_picker:') controller..rightBarButtonItem = right if self.formViewController.presentedViewController self.formViewController.dismissViewControllerAnimated(true, completion: -> { self.formViewController.presentViewController(, animated: true, completion: nil) }) else self.formViewController.presentViewController(, animated: true, completion: nil) end end end end |
#update ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ProMotion/XLForm/cells/xl_form_color_selector_cell.rb', line 70 def update super.tap do self.textLabel.text = (self.rowDescriptor.isRequired and self.rowDescriptor.title) ? "#{self.rowDescriptor.title}*" : self.rowDescriptor.title @color_view.frame = [[305.0, 7.0], [80.0, 30.0]] color = self.rowDescriptor.value unless color color = UIColor.whiteColor end @color_view.layer.borderColor = UIColor.blackColor.CGColor @color_view.backgroundColor = color self.textLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) end end |