Class: ISDColorPaletteViewController

Inherits:
UIViewController
  • Object
show all
Defined in:
lib/isd-color-palette/controller/isd_color_palette_view_controller.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#color_layerObject (readonly)

Returns the value of attribute color_layer.



15
16
17
# File 'lib/isd-color-palette/controller/isd_color_palette_view_controller.rb', line 15

def color_layer
  @color_layer
end

#colorNameLabelObject

IBOutlet UILabel



5
6
7
# File 'lib/isd-color-palette/controller/isd_color_palette_view_controller.rb', line 5

def colorNameLabel
  @colorNameLabel
end

#colorWellViewObject

IBOutlet UIView



4
5
6
# File 'lib/isd-color-palette/controller/isd_color_palette_view_controller.rb', line 4

def colorWellView
  @colorWellView
end

#return_nilObject

If it’s true, return nil when the color is the clear color.



12
13
14
# File 'lib/isd-color-palette/controller/isd_color_palette_view_controller.rb', line 12

def return_nil
  @return_nil
end

#selected_color_blockObject

-> {|color| }



9
10
11
# File 'lib/isd-color-palette/controller/isd_color_palette_view_controller.rb', line 9

def selected_color_block
  @selected_color_block
end

#selectedColorObject

Returns the value of attribute selectedColor.



7
8
9
# File 'lib/isd-color-palette/controller/isd_color_palette_view_controller.rb', line 7

def selectedColor
  @selectedColor
end

#solid_layerObject (readonly)

Returns the value of attribute solid_layer.



15
16
17
# File 'lib/isd-color-palette/controller/isd_color_palette_view_controller.rb', line 15

def solid_layer
  @solid_layer
end

Class Method Details

.colorPaletteViewControllerObject



19
20
21
22
# File 'lib/isd-color-palette/controller/isd_color_palette_view_controller.rb', line 19

def colorPaletteViewController
  sb = UIStoryboard.storyboardWithName "ISDColorPalette", bundle:nil
  sb.instantiateViewControllerWithIdentifier "ISDColorPaletteViewController"
end

Instance Method Details

#didChangeColor(color) ⇒ Object

def supportedInterfaceOrientations

  UIInterfaceOrientationMaskPortrait
end


111
112
113
114
115
116
117
# File 'lib/isd-color-palette/controller/isd_color_palette_view_controller.rb', line 111

def didChangeColor color
  self.selectedColor = color
  if self.selected_color_block
    color = nil if self.return_nil && color.alpha == 0
    self.selected_color_block.call color
  end
end

#viewDidLoadObject

def initWithNibName nibNameOrNil, bundle:nibBundleOrNil

  super
  self
end


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/isd-color-palette/controller/isd_color_palette_view_controller.rb', line 33

def viewDidLoad
  super
  l = colorWellView.layer
  l.borderColor = :black.uicolor.cgcolor
  l.borderWidth = 2
  l.cornerRadius = 4
  l.masksToBounds = true
  @color_layer = l
  
  @solid_layer = CALayer.new
  r2 = Math.sqrt 2
  w = h = @color_layer.frame.size.height * r2
  x = CGRectGetMaxX(@color_layer.bounds) - w / 2
  y = -h / 2
  @solid_layer.frame = CGRectMake(x, y, w, h)
  rad = 45 * Math::PI / 180
  @solid_layer.transform = CATransform3DMakeRotation(rad, 0, 0, 1)
  @color_layer.addSublayer @solid_layer
  
  set_color self.selectedColor
end