class UITextView

Methods which use blocks for UITextViewDelegate methods. EX field.should_end? do |text_field|

if text_field.text != "secret"
  return false
end
true

end

Also includes an on_change method, which calls after the text has changed (there is no UITextViewDelegate equivalent.) EX field.on_change do |text_field|

p text_field.text

end

Attributes

placeholder[R]
placeholder_color[RW]

Public Instance Methods

dealloc() click to toggle source
# File lib/formotion/patch/ui_text_view_placeholder.rb, line 26
def dealloc
  NSNotificationCenter.defaultCenter.unobserve @foreground_observer
  old_dealloc
end
Also aliased as: old_dealloc
drawRect(rect) click to toggle source
# File lib/formotion/patch/ui_text_view_placeholder.rb, line 32
def drawRect(rect)
  old_drawRect(rect)

  if (@shouldDrawPlaceholder)
      self.placeholder_color.set
      self.font ||= UIFont.systemFontOfSize(17) # ios7 seems to have a bug where font of uitextview isn't set by default
      self.placeholder.drawInRect(placeholder_rect, withFont:self.font)
  end
end
Also aliased as: old_drawRect
initWithCoder(decoder) click to toggle source
# File lib/formotion/patch/ui_text_view_placeholder.rb, line 6
def initWithCoder(decoder)
  old_initWithCoder(decoder)
  setup
  self
end
Also aliased as: old_initWithCoder
initWithFrame(frame) click to toggle source
# File lib/formotion/patch/ui_text_view_placeholder.rb, line 13
def initWithFrame(frame)
  old_initWithFrame(frame)
  setup
  self
end
Also aliased as: old_initWithFrame
old_dealloc()
Alias for: dealloc
old_drawRect(rect)
Alias for: drawRect
old_initWithCoder(decoder)
Alias for: initWithCoder
old_initWithFrame(frame)
Alias for: initWithFrame
old_setText(text)
Alias for: setText
on_begin(&block) click to toggle source

block takes argument textView

# File lib/formotion/patch/ui_text_view.rb, line 26
def on_begin(&block)
  add_delegate_method do
    @delegate.textViewDidBeginEditing_callback = block
  end
end
on_change(&block) click to toggle source

block takes argument textView

# File lib/formotion/patch/ui_text_view.rb, line 47
def on_change(&block)
  add_delegate_method do
    @delegate.textViewDidChange_callback = block
  end
end
on_end(&block) click to toggle source

block takes argument textView

# File lib/formotion/patch/ui_text_view.rb, line 40
def on_end(&block)
  add_delegate_method do
    @delegate.textViewDidEndEditing_callback = block
  end
end
placeholder=(placeholder) click to toggle source
# File lib/formotion/patch/ui_text_view_placeholder.rb, line 50
def placeholder=(placeholder)
  return if @placeholder == placeholder

  @placeholder = placeholder

  updateShouldDrawPlaceholder
end
placeholder_rect() click to toggle source
# File lib/formotion/patch/ui_text_view_placeholder.rb, line 58
def placeholder_rect
  x_offset = font.xHeight
  y_offset = font.capHeight + font.descender

  CGRectMake(self.contentInset.left + x_offset, self.contentInset.top + y_offset, self.frame.size.width - self.contentInset.left - self.contentInset.right - x_offset, self.frame.size.height - self.contentInset.top - self.contentInset.bottom - y_offset)
end
setText(text) click to toggle source
# File lib/formotion/patch/ui_text_view_placeholder.rb, line 44
def setText(text)
  old_setText(text)

  updateShouldDrawPlaceholder
end
Also aliased as: old_setText
setup() click to toggle source
# File lib/formotion/patch/ui_text_view_placeholder.rb, line 19
def setup
  @foreground_observer = NSNotificationCenter.defaultCenter.observe UITextViewTextDidChangeNotification do |notification|
    updateShouldDrawPlaceholder
  end
end
should_begin?(&block) click to toggle source

block takes argument textView; should return true/false

# File lib/formotion/patch/ui_text_view.rb, line 19
def should_begin?(&block)
  add_delegate_method do
    @delegate.textViewShouldBeginEditing_callback = block
  end
end
should_change?(&block) click to toggle source

block takes argument textView, range [NSRange], and string; should return true/false

# File lib/formotion/patch/ui_text_view.rb, line 54
def should_change?(&block)
  add_delegate_method do
    @delegate.shouldChangeCharactersInRange_callback = block
  end
end
should_end?(&block) click to toggle source

block takes argument textView; should return true/false

# File lib/formotion/patch/ui_text_view.rb, line 33
def should_end?(&block)
  add_delegate_method do
    @delegate.textViewShouldEndEditing_callback = block
  end
end
updateShouldDrawPlaceholder() click to toggle source
# File lib/formotion/patch/ui_text_view_placeholder.rb, line 69
def updateShouldDrawPlaceholder
  prev = @shouldDrawPlaceholder;
  @shouldDrawPlaceholder = self.placeholder && self.text.length == 0

  self.setNeedsDisplay if (prev != @shouldDrawPlaceholder)
end

Private Instance Methods

add_delegate_method() { || ... } click to toggle source
# File lib/formotion/patch/ui_text_view.rb, line 61
def add_delegate_method
  # create strong reference to the delegate
  # (.delegate= only creates a weak reference)
  @delegate ||= UITextView_Delegate.new
  yield
  self.delegate = @delegate
end