Class: MPTextView
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#apply_padding, #apply_padding!, #apply_padding?, #padding_bottom, #padding_insets, #padding_left, #padding_right, #padding_top
#setValue
Instance Attribute Details
#placeholder ⇒ Object
Returns the value of attribute placeholder.
10
11
12
|
# File 'motion-prime/support/mp_text_view.rb', line 10
def placeholder
@placeholder
end
|
#placeholderColor ⇒ Object
Returns the value of attribute placeholderColor.
10
11
12
|
# File 'motion-prime/support/mp_text_view.rb', line 10
def placeholderColor
@placeholderColor
end
|
#placeholderFont ⇒ Object
Returns the value of attribute placeholderFont.
10
11
12
|
# File 'motion-prime/support/mp_text_view.rb', line 10
def placeholderFont
@placeholderFont
end
|
Class Method Details
.default_padding_left ⇒ Object
12
13
14
|
# File 'motion-prime/support/mp_text_view.rb', line 12
def self.default_padding_left
5
end
|
.default_padding_right ⇒ Object
16
17
18
|
# File 'motion-prime/support/mp_text_view.rb', line 16
def self.default_padding_right
5
end
|
Instance Method Details
#drawPadding(rect) ⇒ Object
20
21
22
23
24
|
# File 'motion-prime/support/mp_text_view.rb', line 20
def drawPadding(rect)
self.textContainer.lineFragmentPadding = 0 self.textContainerInset = self.padding_insets
end
|
#drawPlaceholder(rect) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'motion-prime/support/mp_text_view.rb', line 26
def drawPlaceholder(rect)
padding = UIEdgeInsetsMake(
padding_top, padding_left,
padding_bottom, padding_right
)
if self.placeholder && self.text.blank?
color = self.placeholderColor || :gray.uicolor
color.setFill
font = self.placeholderFont || self.font || :system.uifont(16)
color.setFill
rect = CGRectMake(
rect.origin.x + padding_left,
rect.origin.y + padding_top,
self.frame.size.width - padding_left,
self.frame.size.height - padding_top
)
placeholder.drawInRect(rect, withFont: font)
end
end
|
#drawRect(rect) ⇒ Object
47
48
49
50
51
|
# File 'motion-prime/support/mp_text_view.rb', line 47
def drawRect(rect)
drawPadding(rect)
drawPlaceholder(rect)
super
end
|
#initPlaceholder ⇒ Object
53
54
55
56
57
58
|
# File 'motion-prime/support/mp_text_view.rb', line 53
def initPlaceholder
NSNotificationCenter.defaultCenter.addObserver(self,
selector: :textChanged, name: UITextViewTextDidChangeNotification, object: self
)
@shouldDrawPlaceholder = placeholder && self.text.blank?
end
|
#initWithCoder(aDecoder) ⇒ Object
73
74
75
76
77
78
|
# File 'motion-prime/support/mp_text_view.rb', line 73
def initWithCoder(aDecoder)
if super
initPlaceholder
end
self
end
|
#initWithFrame(frame) ⇒ Object
80
81
82
83
84
85
|
# File 'motion-prime/support/mp_text_view.rb', line 80
def initWithFrame(frame)
if super
initPlaceholder
end
self
end
|
#textChanged ⇒ Object
60
61
62
|
# File 'motion-prime/support/mp_text_view.rb', line 60
def textChanged
updatePlaceholderDraw
end
|
#updatePlaceholderDraw ⇒ Object
64
65
66
67
68
69
70
|
# File 'motion-prime/support/mp_text_view.rb', line 64
def updatePlaceholderDraw
prev = @shouldDrawPlaceholder
@shouldDrawPlaceholder = placeholder && self.text.blank?
if prev != @shouldDrawPlaceholder
self.setNeedsDisplay
end
end
|