Class: MPButton

Inherits:
UIButton
  • Object
show all
Includes:
MotionPrime::SupportKeyValueStore, MotionPrime::SupportPaddingAttribute
Defined in:
motion-prime/support/mp_button.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MotionPrime::SupportPaddingAttribute

#apply_padding, #padding_insets, #padding_left, #padding_right

Methods included from MotionPrime::SupportKeyValueStore

#setValue

Instance Attribute Details

#sizeToFitObject

Returns the value of attribute sizeToFit.



4
5
6
# File 'motion-prime/support/mp_button.rb', line 4

def sizeToFit
  @sizeToFit
end

Class Method Details

.default_padding_leftObject



19
20
21
# File 'motion-prime/support/mp_button.rb', line 19

def self.default_padding_left
  5
end

.default_padding_rightObject



23
24
25
# File 'motion-prime/support/mp_button.rb', line 23

def self.default_padding_right
  5
end

Instance Method Details

#apply_padding!(rect) ⇒ Object



38
39
40
# File 'motion-prime/support/mp_button.rb', line 38

def apply_padding!(rect)
  self.setTitleEdgeInsets(padding_insets)
end

#apply_padding?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'motion-prime/support/mp_button.rb', line 42

def apply_padding?
  super && !@custom_title_inset_drawn
end

#drawRect(rect) ⇒ Object



46
47
48
49
# File 'motion-prime/support/mp_button.rb', line 46

def drawRect(rect)
  apply_padding(rect)
  super
end

#padding_bottomObject



34
35
36
# File 'motion-prime/support/mp_button.rb', line 34

def padding_bottom
  self.bounds.size.height - (self.font.pointSize + padding_top)
end

#padding_topObject

to center title label



27
28
29
30
31
32
# File 'motion-prime/support/mp_button.rb', line 27

def padding_top # to center title label
  self.paddingTop || self.padding || begin
    single_line_height = self.font.pointSize
    (self.bounds.size.height - single_line_height)/2 + 1
  end
end

#setImage(value) ⇒ Object



10
11
12
# File 'motion-prime/support/mp_button.rb', line 10

def setImage(value)
  setImage value, forState: UIControlStateNormal
end

#setTitle(value) ⇒ Object



6
7
8
# File 'motion-prime/support/mp_button.rb', line 6

def setTitle(value)
  setTitle value, forState: UIControlStateNormal
end

#setTitleEdgeInsets(value) ⇒ Object



14
15
16
17
# File 'motion-prime/support/mp_button.rb', line 14

def setTitleEdgeInsets(value)
  @custom_title_inset_drawn = true
  super
end