Created
February 14, 2014 10:44
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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