Class: MMDrawerMenuButtonView

Inherits:
UIButton
  • Object
show all
Defined in:
lib/liam/MMDrawerBarButtonView.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

Returns the value of attribute menuButtonHighlightedColor.



4
5
6
# File 'lib/liam/MMDrawerBarButtonView.rb', line 4

def menuButtonHighlightedColor
  @menuButtonHighlightedColor
end

Returns the value of attribute menuButtonNormalColor.



3
4
5
# File 'lib/liam/MMDrawerBarButtonView.rb', line 3

def menuButtonNormalColor
  @menuButtonNormalColor
end

#shadowHighlightedColorObject

Returns the value of attribute shadowHighlightedColor.



6
7
8
# File 'lib/liam/MMDrawerBarButtonView.rb', line 6

def shadowHighlightedColor
  @shadowHighlightedColor
end

#shadowNormalColorObject

Returns the value of attribute shadowNormalColor.



5
6
7
# File 'lib/liam/MMDrawerBarButtonView.rb', line 5

def shadowNormalColor
  @shadowNormalColor
end

Instance Method Details

#drawRect(rect) ⇒ Object

def drawRect:(CGRect)rect{



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/liam/MMDrawerBarButtonView.rb', line 73

def drawRect(rect)
    # General Declarations
    context = UIGraphicsGetCurrentContext() #CGContextRef 
    
    # Sizes
    buttonWidth = CGRectGetWidth(self.bounds) * 0.80
    buttonHeight = CGRectGetHeight(self.bounds) * 0.16
    xOffset = CGRectGetWidth(self.bounds) * 0.10
    yOffset = CGRectGetHeight(self.bounds) * 0.12
    cornerRadius = 1.0
    
    # Color Declarations
    buttonColor = self.menuButtonColorForState(self.state)
    shadowColor = self.shadowColorForState(self.state)

    
    # Shadow Declarations
    shadow =  shadowColor
    shadowOffset = CGSizeMake(0.0, 1.0)
    shadowBlurRadius = 0
    
    # Top Bun Drawing
    topBunPath = UIBezierPath.bezierPathWithRoundedRect(CGRectMake(xOffset, yOffset, buttonWidth, buttonHeight), cornerRadius:cornerRadius) # UIBezierPath
    CGContextSaveGState(context)
      CGContextSetShadowWithColor(context, shadowOffset, shadowBlurRadius, shadow.CGColor)
      buttonColor.setFill
      topBunPath.fill
    CGContextRestoreGState(context)
    
    # Meat Drawing
    meatPath = UIBezierPath.bezierPathWithRoundedRect(CGRectMake(xOffset, yOffset*2 + buttonHeight, buttonWidth, buttonHeight), cornerRadius:cornerRadius) # UIBezierPath* 
    CGContextSaveGState(context)
      CGContextSetShadowWithColor(context, shadowOffset, shadowBlurRadius, shadow.CGColor)
      buttonColor.setFill
      meatPath.fill
    CGContextRestoreGState(context)
    
    # Bottom Bun Drawing
    bottomBunPath = UIBezierPath.bezierPathWithRoundedRect(CGRectMake(xOffset, yOffset*3 + buttonHeight*2, buttonWidth, buttonHeight), cornerRadius:cornerRadius) # UIBezierPath* 
    CGContextSaveGState(context)
      CGContextSetShadowWithColor(context, shadowOffset, shadowBlurRadius, shadow.CGColor)
      buttonColor.setFill
      bottomBunPath.fill
    CGContextRestoreGState(context)
end

#highlighted=(highlighted) ⇒ Object

def setHighlighted:(BOOL)highlighted{



144
145
146
147
# File 'lib/liam/MMDrawerBarButtonView.rb', line 144

def highlighted=(highlighted) 
  super
  self.setNeedsDisplay
end

#initWithFrame(frame) ⇒ Object

def initWithFrame:(CGRect)frame{



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/liam/MMDrawerBarButtonView.rb', line 9

def initWithFrame(frame)
  # self = super.initWithFrame(frame)
  if(super)
      self.setMenuButtonNormalColor(UIColor.whiteColor.colorWithAlphaComponent(0.9))
      self.setMenuButtonHighlightedColor(UIColor.colorWithRed(139.0/255.0, green:135.0/255.0, blue:136.0/255.0, alpha:0.9))
      
      self.setShadowNormalColor(UIColor.blackColor.colorWithAlphaComponent(0.5))
      self.setShadowHighlightedColor(UIColor.blackColor.colorWithAlphaComponent(0.2))
  end
  return self
end

def menuButtonColorForState:(UIControlState)state{



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/liam/MMDrawerBarButtonView.rb', line 22

def menuButtonColorForState(state)
    color = UIColor.greenColor # A default color just in case, get it, that was funny.

    case (state)
    when UIControlStateNormal
      color = self.menuButtonNormalColor
    when UIControlStateHighlighted
      color = self.menuButtonHighlightedColor
    end

    return color
end

#selected=(selected) ⇒ Object

def setSelected:(BOOL)selected{



138
139
140
141
# File 'lib/liam/MMDrawerBarButtonView.rb', line 138

def selected=(selected)
  super
  self.setNeedsDisplay
end

#setMenuButtonColor(color, forState: state) ⇒ Object

def setMenuButtonColor:(UIColor *)color forState:(UIControlState)state{



36
37
38
39
40
41
42
43
44
45
# File 'lib/liam/MMDrawerBarButtonView.rb', line 36

def setMenuButtonColor(color, forState:state)
    case (state)
    when UIControlStateNormal
      self.setMenuButtonNormalColor(color)
    when UIControlStateHighlighted
      self.setMenuButtonHighlightedColor(color)
    end

    self.setNeedsDisplay
end

#setShadowColor(color, forState: state) ⇒ Object

def setShadowColor:(UIColor *)color forState:(UIControlState)state{



62
63
64
65
66
67
68
69
70
# File 'lib/liam/MMDrawerBarButtonView.rb', line 62

def setShadowColor(color, forState:state)
    case (state)
    when UIControlStateNormal
      self.setShadowNormalColor(color)
    when UIControlStateHighlighted
      self.setShadowHighlightedColor(color)
    end
    self.setNeedsDisplay
end

#shadowColorForState(state) ⇒ Object

def shadowColorForState:(UIControlState)state{



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/liam/MMDrawerBarButtonView.rb', line 48

def shadowColorForState(state)
    color = UIColor.redColor # A default color 

    case (state)
    when UIControlStateNormal
      color = self.shadowNormalColor
    when UIControlStateHighlighted
      color = self.shadowHighlightedColor
    end

    return color
end

#touchesBegan(touches, withEvent: event) ⇒ Object

def touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{



120
121
122
123
# File 'lib/liam/MMDrawerBarButtonView.rb', line 120

def touchesBegan(touches, withEvent:event)
  super
  self.setNeedsDisplay
end

#touchesCancelled(touches, withEvent: event) ⇒ Object

def touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{



132
133
134
135
# File 'lib/liam/MMDrawerBarButtonView.rb', line 132

def touchesCancelled(touches, withEvent:event)
  super
  self.setNeedsDisplay
end

#touchesEnded(touches, withEvent: event) ⇒ Object

def touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{



126
127
128
129
# File 'lib/liam/MMDrawerBarButtonView.rb', line 126

def touchesEnded(touches, withEvent:event)
  super
  self.setNeedsDisplay
end