Class: ISDRgbaSliderView
- Inherits:
-
UIView
- Object
- UIView
- ISDRgbaSliderView
- Defined in:
- lib/isd-color-palette/view/isd_rgba_slider_view.rb
Instance Attribute Summary collapse
-
#color_value ⇒ Object
Returns the value of attribute color_value.
-
#identity ⇒ Object
Returns the value of attribute identity.
-
#idLabel ⇒ Object
IBOutlet UILabel.
-
#slider ⇒ Object
readonly
Returns the value of attribute slider.
-
#sliderBaseView ⇒ Object
IBOutlet UIView.
-
#valueTextField ⇒ Object
IBOutlet UITextField.
-
#viewController ⇒ Object
IBOutlet UIViewController.
Instance Method Summary collapse
-
#awakeFromNib ⇒ Object
def initWithCorder decode super self end.
- #color=(color) ⇒ Object
-
#didChangeValue(sender) ⇒ Object
def shouldAutorotateToInterfaceOrientation interfaceOrientation interfaceOrientation == UIInterfaceOrientationPortrait end.
- #hide_keyboard(textField = self.valueTextField) ⇒ Object
- #layoutSubviews ⇒ Object
- #set_backgournd_color ⇒ Object
- #set_color_value_to_controls ⇒ Object
-
#textFieldDidEndEditing(textField) ⇒ Object
UITextField delegate.
- #textFieldShouldReturn(textField) ⇒ Object
Instance Attribute Details
#color_value ⇒ Object
Returns the value of attribute color_value.
9 10 11 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 9 def color_value @color_value end |
#identity ⇒ Object
Returns the value of attribute identity.
10 11 12 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 10 def identity @identity end |
#idLabel ⇒ Object
IBOutlet UILabel
7 8 9 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 7 def idLabel @idLabel end |
#slider ⇒ Object (readonly)
Returns the value of attribute slider.
12 13 14 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 12 def @slider end |
#sliderBaseView ⇒ Object
IBOutlet UIView
5 6 7 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 5 def @sliderBaseView end |
#valueTextField ⇒ Object
IBOutlet UITextField
6 7 8 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 6 def valueTextField @valueTextField end |
#viewController ⇒ Object
IBOutlet UIViewController
4 5 6 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 4 def viewController @viewController end |
Instance Method Details
#awakeFromNib ⇒ Object
def initWithCorder decode
super
self
end
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 28 def awakeFromNib l = self.layer l.borderColor = :white.uicolor.cgcolor l.borderWidth = 3 l.cornerRadius = 4 # setup slider @slider = UISlider.new @slider.frame = CGRectInset .bounds, 0, 8 rad = -90 * Math::PI / 180 @slider.transform = CGAffineTransformMakeRotation(rad) << @slider @slider.addTarget self, action:"didChangeValue:", forControlEvents:UIControlEventValueChanged end |
#color=(color) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 55 def color= color @color = color @color_value = 0 if color case self.identity when "R" @color_value = color.red when "G" @color_value = color.green when "B" @color_value = color.blue when "A" @color_value = color.alpha end set_color_value_to_controls set_backgournd_color end end |
#didChangeValue(sender) ⇒ Object
def shouldAutorotateToInterfaceOrientation interfaceOrientation
interfaceOrientation == UIInterfaceOrientationPortrait
end
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 87 def didChangeValue sender # IBAction case sender when UISlider @color_value = sender.value when UITextField @color_value = sender.text.to_f / 255.0 end set_color_value_to_controls self.viewController.didChangeColor sender end |
#hide_keyboard(textField = self.valueTextField) ⇒ Object
131 132 133 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 131 def hide_keyboard textField = self.valueTextField textField.resignFirstResponder if textField end |
#layoutSubviews ⇒ Object
47 48 49 50 51 52 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 47 def layoutSubviews super return unless self. self..frame = CGRectInset self..bounds, 0, 8 end |
#set_backgournd_color ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 103 def set_backgournd_color case self.identity when "R" bg_color = :red.uicolor when "G" bg_color = :green.uicolor when "B" bg_color = :blue.uicolor when "A" bg_color = :white.uicolor end self.backgroundColor = :black.uicolor.mix_with bg_color, self.color_value self.idLabel.textColor = UIColor.colorWithWhite(self.color_value, alpha:1.0).invert if self.idLabel end |
#set_color_value_to_controls ⇒ Object
98 99 100 101 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 98 def set_color_value_to_controls self.valueTextField.text = [(self.color_value * 255 + 0.5), 255.0].min.to_i.to_s self..value = self.color_value end |
#textFieldDidEndEditing(textField) ⇒ Object
UITextField delegate
119 120 121 122 123 124 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 119 def textFieldDidEndEditing(textField) if /^\s*\d+\s*$/ =~ textField.text @color_value = [textField.text.to_i, 255].min / 255.0 end didChangeValue self end |
#textFieldShouldReturn(textField) ⇒ Object
126 127 128 129 |
# File 'lib/isd-color-palette/view/isd_rgba_slider_view.rb', line 126 def textFieldShouldReturn(textField) hide_keyboard textField true end |