Class: TextFieldCell
- Inherits:
-
BaseCell
- Object
- UITableViewCell
- BaseCell
- TextFieldCell
show all
- Defined in:
- lib/project/cells/text_field_cell.rb
Constant Summary
collapse
- IDENTIFIER =
'TextFieldCell'
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
17
18
19
|
# File 'lib/project/cells/text_field_cell.rb', line 17
def has_value?
true
end
|
Instance Method Details
#capitalize=(bool) ⇒ Object
99
100
101
102
103
|
# File 'lib/project/cells/text_field_cell.rb', line 99
def capitalize=(bool)
option = bool ? UITextAutocapitalizationTypeSentences : UITextAutocapitalizationTypeNone
text_view.autocapitalizationType = option
end
|
#initWithStyle(style, reuseIdentifier: reuse_identifier) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/project/cells/text_field_cell.rb', line 6
def initWithStyle(style, reuseIdentifier: reuse_identifier)
super.tap do |cell|
cell.observe('ButtonCallbackWillFire', 'resign_text_view:')
cell.observe('FormWillValidate', 'resign_text_view:')
cell.observe('FormWillRender', 'resign_text_view:')
cell.setup_constraints
end
end
|
#label=(label) ⇒ Object
35
36
|
# File 'lib/project/cells/text_field_cell.rb', line 35
def label=(label)
end
|
#notification_payload ⇒ Object
105
106
107
|
# File 'lib/project/cells/text_field_cell.rb', line 105
def notification_payload
{ key: key, value: value, text_field: text_view }
end
|
#placeholder=(placeholder) ⇒ Object
38
39
40
|
# File 'lib/project/cells/text_field_cell.rb', line 38
def placeholder=(placeholder)
text_view.placeholder = placeholder
end
|
#resign_text_view(notification) ⇒ Object
31
32
33
|
# File 'lib/project/cells/text_field_cell.rb', line 31
def resign_text_view(notification)
text_view.resignFirstResponder if text_view.isFirstResponder
end
|
#secure=(secure) ⇒ Object
42
43
|
# File 'lib/project/cells/text_field_cell.rb', line 42
def secure=(secure)
end
|
#setup_constraints ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/project/cells/text_field_cell.rb', line 22
def setup_constraints
Motion::Layout.new do |layout|
layout.view contentView
layout.subviews 'text_view' => text_view
layout.horizontal '|[text_view]|'
layout.vertical '|[text_view]|'
end
end
|
#text_view ⇒ Object
Also known as:
text_field
45
46
47
48
49
50
|
# File 'lib/project/cells/text_field_cell.rb', line 45
def text_view
@text_view ||= SZTextView.alloc.init.tap do |text_view|
text_view.font = UIFont.fontWithName('HelveticaNeue-Light', size: 14.0)
text_view.delegate = self
end
end
|
#textFieldShouldReturn(text_view) ⇒ Object
69
70
71
72
73
|
# File 'lib/project/cells/text_field_cell.rb', line 69
def textFieldShouldReturn(text_view)
text_view.resignFirstResponder
true
end
|
#textView(text_view, shouldChangeTextInRange: range, replacementText: text) ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/project/cells/text_field_cell.rb', line 75
def textView(text_view, shouldChangeTextInRange: range, replacementText: text)
if text == "\n"
text_view.resignFirstResponder
false
else
true
end
end
|
#textViewDidBeginEditing(text_view) ⇒ Object
61
62
63
|
# File 'lib/project/cells/text_field_cell.rb', line 61
def textViewDidBeginEditing(text_view)
post('FormCellDidBeginEditing', notification_payload)
end
|
#textViewDidChange(text_view) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/project/cells/text_field_cell.rb', line 85
def textViewDidChange(text_view)
line = text_view.caretRectForPosition(text_view..start)
overflow = line.origin.y + line.size.height - (text_view.contentOffset.y + text_view.bounds.size.height - text_view.contentInset.bottom - text_view.contentInset.top )
if overflow > 0
offset = text_view.contentOffset
offset.y += overflow + 7
UIView.animateWithDuration(0.2, animations: -> {
text_view.setContentOffset(offset)
})
end
end
|
#textViewDidEndEditing(text_view) ⇒ Object
65
66
67
|
# File 'lib/project/cells/text_field_cell.rb', line 65
def textViewDidEndEditing(text_view)
post('FormCellDidEndEditing', notification_payload)
end
|
#value ⇒ Object
53
54
55
|
# File 'lib/project/cells/text_field_cell.rb', line 53
def value
text_view.text
end
|
#value=(value) ⇒ Object
57
58
59
|
# File 'lib/project/cells/text_field_cell.rb', line 57
def value=(value)
text_view.text = value
end
|