Skip to content

Instantly share code, notes, and snippets.

@colinta
Created August 2, 2013 22:27
Show Gist options
  • Save colinta/6143990 to your computer and use it in GitHub Desktop.
Save colinta/6143990 to your computer and use it in GitHub Desktop.
class InsetTextField < UITextField
attr :edgeInsets
def init
initWithFrame(CGRectZero)
end
def initWithFrame(frame)
super.tap do
@edgeInsets = [0, 0, 0, 0]
end
end
def awakeFromNib
@edgeInsets = [0, 0, 0, 0]
end
def edgeInsets=(val)
@edgeInsets = val
setNeedsDisplay
end
# placeholder position
def placeholderRectForBounds(bounds)
UIEdgeInsetsInsetRect(bounds, @edgeInsets)
end
# text position
def textRectForBounds(bounds)
UIEdgeInsetsInsetRect(bounds, @edgeInsets)
end
# editing position
def editingRectForBounds(bounds)
# super
UIEdgeInsetsInsetRect(bounds, @edgeInsets)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment