Class: TextInputCell
- Inherits:
-
BaseCell
- Object
- UITableViewCell
- BaseCell
- TextInputCell
show all
- Defined in:
- lib/project/cells/text_input_cell.rb
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
48
49
50
|
# File 'lib/project/cells/text_input_cell.rb', line 48
def has_value?
true
end
|
Instance Method Details
#capitalize=(bool) ⇒ Object
111
112
113
114
115
|
# File 'lib/project/cells/text_input_cell.rb', line 111
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
57
58
59
|
# File 'lib/project/cells/text_input_cell.rb', line 57
def label=(label)
text_label.text = label
end
|
#notification_payload ⇒ Object
117
118
119
|
# File 'lib/project/cells/text_input_cell.rb', line 117
def notification_payload
{ key: key, value: value, text_field: text_field }
end
|
#placeholder=(placeholder) ⇒ Object
65
66
67
|
# File 'lib/project/cells/text_input_cell.rb', line 65
def placeholder=(placeholder)
text_field.placeholder = placeholder
end
|
#resign_textfield(notification) ⇒ Object
53
54
55
|
# File 'lib/project/cells/text_input_cell.rb', line 53
def resign_textfield(notification)
text_field.resignFirstResponder if text_field.isFirstResponder
end
|
#secure=(secure) ⇒ Object
61
62
63
|
# File 'lib/project/cells/text_input_cell.rb', line 61
def secure=(secure)
text_field.secureTextEntry = secure
end
|
#setup_constraints ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# 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_dict ⇒ Object
42
43
44
45
|
# File 'lib/project/cells/text_input_cell.rb', line 42
def subviews_dict
{ 'label' => text_label,
'input' => text_field }
end
|
#text_field ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/project/cells/text_input_cell.rb', line 69
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_label ⇒ Object
82
83
84
85
86
87
|
# File 'lib/project/cells/text_input_cell.rb', line 82
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
97
98
99
|
# File 'lib/project/cells/text_input_cell.rb', line 97
def textFieldDidBeginEditing(text_field)
post('FormCellDidBeginEditing', notification_payload)
end
|
#textFieldDidEndEditing(text_field) ⇒ Object
101
102
103
|
# File 'lib/project/cells/text_input_cell.rb', line 101
def textFieldDidEndEditing(text_field)
post('FormCellDidEndEditing', notification_payload)
end
|
#textFieldShouldReturn(text_field) ⇒ Object
105
106
107
108
109
|
# File 'lib/project/cells/text_input_cell.rb', line 105
def textFieldShouldReturn(text_field)
text_field.resignFirstResponder
true
end
|
#value ⇒ Object
89
90
91
|
# File 'lib/project/cells/text_input_cell.rb', line 89
def value
text_field.text
end
|
#value=(value) ⇒ Object
93
94
95
|
# File 'lib/project/cells/text_input_cell.rb', line 93
def value=(value)
text_field.text = value
end
|