Created
January 25, 2014 23:22
-
-
Save pierceboggan/8625385 to your computer and use it in GitHub Desktop.
An easy way to implement your own UITextView placeholder field without subclassing.
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
public class CommentsTextDelegate : UITextViewDelegate | |
{ | |
public override void EditingStarted (UITextView textView) | |
{ | |
if (textView.Text == "Comments") { | |
textView.Text = ""; | |
textView.TextColor = UIColor.Black; | |
textView.Font = FontConstants.SourceSansProRegular (13); | |
} | |
textView.BecomeFirstResponder (); | |
} | |
public override void EditingEnded (UITextView textView) | |
{ | |
if (textView.Text == "") { | |
textView.Text = "Comments"; | |
textView.TextColor = UIColor.LightGray; | |
textView.Font = FontConstants.SourceSansProBold (13); | |
} | |
textView.ResignFirstResponder (); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment