Skip to content

Instantly share code, notes, and snippets.

@alloy
Created February 14, 2014 10:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alloy/8999108 to your computer and use it in GitHub Desktop.
Save alloy/8999108 to your computer and use it in GitHub Desktop.
Some controls have internal subviews you’d want to modify, but you cannot control the class that’s used internally. This example shows extending just that singleton (the view instance) by defining the method inline. This is preferable to using ‘categories’, because those affect _all_ instances of that class.
def presentAlert
alert = UIAlertView.new
# ...
textField = alert.textFieldAtIndex(0)
# *Only for this UITextField instance*, move the leftView 4 points to the right.
def textField.leftViewRectForBounds(bounds)
CGRectOffset(super, 4, 0)
end
alert.show
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment