Class: TextInputCell

Inherits:
BaseCell
  • Object
show all
Defined in:
lib/project/cells/text_input_cell.rb

Direct Known Subclasses

ButtonCell

Constant Summary collapse

IDENTIFIER =
'TextInputCell'

Instance Attribute Summary

Attributes inherited from BaseCell

#key

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCell

#dealloc, #notification_center, #observe, #post, #selected_background_view

Class Method Details

.has_value?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/project/cells/text_input_cell.rb', line 47

def has_value?
  true
end

Instance Method Details

#capitalize=(bool) ⇒ Object



110
111
112
113
114
# File 'lib/project/cells/text_input_cell.rb', line 110

def capitalize=(bool)
  option = bool ? UITextAutocapitalizationTypeSentences : UITextAutocapitalizationTypeNone

  text_field.autocapitalizationType = option
end

#initWithStyle(style, reuseIdentifier: reuse_identifier) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/project/cells/text_input_cell.rb', line 6

def initWithStyle(style, reuseIdentifier: reuse_identifier)
  super.tap do |cell|
    cell.setup_constraints

    cell.observe('ButtonCallbackWillFire', 'resign_textfield:')
    cell.observe('FormWillValidate',       'resign_textfield:')
    cell.observe('FormWillRender',         'resign_textfield:')
  end
end

#label=(label) ⇒ Object



56
57
58
# File 'lib/project/cells/text_input_cell.rb', line 56

def label=(label)
  text_label.text = label
end

#notification_payloadObject



116
117
118
# File 'lib/project/cells/text_input_cell.rb', line 116

def notification_payload
  { key: key, value: value, text_field: text_field }
end

#placeholder=(placeholder) ⇒ Object



64
65
66
# File 'lib/project/cells/text_input_cell.rb', line 64

def placeholder=(placeholder)
  text_field.placeholder = placeholder
end

#resign_textfield(notification) ⇒ Object



52
53
54
# File 'lib/project/cells/text_input_cell.rb', line 52

def resign_textfield(notification)
  text_field.resignFirstResponder if text_field.isFirstResponder
end

#secure=(secure) ⇒ Object



60
61
62
# File 'lib/project/cells/text_input_cell.rb', line 60

def secure=(secure)
  text_field.secureTextEntry = secure
end

#setup_constraintsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/project/cells/text_input_cell.rb', line 16

def setup_constraints
  [text_label, text_field].each do |subview|
    subview.translatesAutoresizingMaskIntoConstraints = false
    contentView.addSubview(subview)
  end

  contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
    'H:|-margin-[label(100@1000)][input]-margin-|',
    options: NSLayoutFormatAlignAllCenterY,
    metrics: { 'margin' => 10 },
    views:   subviews_dict))

  contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
    'V:|[label]|',
    options: 0,
    metrics: {},
    views:   subviews_dict))

  contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
    'V:|[input]|',
    options: 0,
    metrics: {},
    views:   subviews_dict))
end

#subviews_dictObject



41
42
43
44
# File 'lib/project/cells/text_input_cell.rb', line 41

def subviews_dict
  { 'label' => text_label,
    'input' => text_field }
end

#text_fieldObject



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/project/cells/text_input_cell.rb', line 68

def text_field
  @text_field ||= UITextField.alloc.init.tap do |field|
    field.autocorrectionType       = UITextAutocorrectionTypeNo
    field.backgroundColor          = UIColor.clearColor
    field.clearButtonMode          = UITextFieldViewModeWhileEditing
    field.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter
    field.textColor                = UIColor.darkGrayColor
    field.font                     = UIFont.fontWithName('HelveticaNeue-Light', size: 16.0)

    field.delegate = self
  end
end

#text_labelObject



81
82
83
84
85
86
# File 'lib/project/cells/text_input_cell.rb', line 81

def text_label
  @text_label ||= UILabel.alloc.init.tap do |label|
    label.textColor = UIColor.darkGrayColor
    label.font      = UIFont.fontWithName('HelveticaNeue-Light', size: 18.0)
  end
end

#textFieldDidBeginEditing(text_field) ⇒ Object



96
97
98
# File 'lib/project/cells/text_input_cell.rb', line 96

def textFieldDidBeginEditing(text_field)
  post('FormCellDidBeginEditing', notification_payload)
end

#textFieldDidEndEditing(text_field) ⇒ Object



100
101
102
# File 'lib/project/cells/text_input_cell.rb', line 100

def textFieldDidEndEditing(text_field)
  post('FormCellDidEndEditing', notification_payload)
end

#textFieldShouldReturn(text_field) ⇒ Object



104
105
106
107
108
# File 'lib/project/cells/text_input_cell.rb', line 104

def textFieldShouldReturn(text_field)
  text_field.resignFirstResponder

  true
end

#valueObject



88
89
90
# File 'lib/project/cells/text_input_cell.rb', line 88

def value
  text_field.text
end

#value=(value) ⇒ Object



92
93
94
# File 'lib/project/cells/text_input_cell.rb', line 92

def value=(value)
  text_field.text = value
end