Class: MPTextField

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

Overview

This class have some modifications for UITextField:

  • support padding, padding_left, padding_right options

  • support placeholder_color, placeholder_font options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MotionPrime::SupportPaddingAttribute

#apply_padding, #apply_padding!, #apply_padding?, #padding_bottom, #padding_insets, #padding_left, #padding_right

Methods included from MotionPrime::SupportKeyValueStore

#setValue

Instance Attribute Details

#placeholderAlignmentObject

Returns the value of attribute placeholderAlignment.



7
8
9
# File 'motion-prime/support/mp_text_field.rb', line 7

def placeholderAlignment
  @placeholderAlignment
end

#placeholderColorObject

Returns the value of attribute placeholderColor.



7
8
9
# File 'motion-prime/support/mp_text_field.rb', line 7

def placeholderColor
  @placeholderColor
end

#placeholderFontObject

Returns the value of attribute placeholderFont.



7
8
9
# File 'motion-prime/support/mp_text_field.rb', line 7

def placeholderFont
  @placeholderFont
end

#readonlyObject

Returns the value of attribute readonly.



7
8
9
# File 'motion-prime/support/mp_text_field.rb', line 7

def readonly
  @readonly
end

Class Method Details

.default_padding_leftObject



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

def self.default_padding_left
  5
end

.default_padding_rightObject



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

def self.default_padding_right
  5
end

Instance Method Details

#drawPlaceholderInRect(rect) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'motion-prime/support/mp_text_field.rb', line 28

def drawPlaceholderInRect(rect)
  color = self.placeholderColor || :gray.uicolor
  color.setFill
  font = self.placeholderFont || self.font || :system.uifont(16)

  truncation = :tail_truncation.uilinebreakmode
  alignment = (placeholderAlignment || :left)
  alignment = alignment.uitextalignment if alignment.is_a?(Symbol)
  self.placeholder.drawInRect(rect, withFont: font, lineBreakMode: truncation, alignment: alignment)
end

#editingRectForBounds(bounds) ⇒ Object

text position



24
25
26
# File 'motion-prime/support/mp_text_field.rb', line 24

def editingRectForBounds(bounds)
  calculate_rect_for(bounds)
end

#padding_topObject

to center title label



39
40
41
42
43
44
# File 'motion-prime/support/mp_text_field.rb', line 39

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

#textRectForBounds(bounds) ⇒ Object

placeholder position



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

def textRectForBounds(bounds)
  calculate_rect_for(bounds)
end