Hi I am working with iPhone apps, I know the UITextfield has placeholder property. But UITextview doesn't have placeholder property. I know the process how to customize placeholder for UITextview. But please let me know the difference.
and UITextfield inherits from UIControl which inturns inherits from UIView...NSObject. and UITextview inherits from UIScrollView, UIView,UIresponder...NSOBject. But where is the difference frome place holder property.
How textfield contains placeholder property, why textview doesn't contain placeholder?
Please give any ideas, suggestions, and/or give better explanation.
The string that displays when there is no other text in the text field.
An object that displays an editable text area in your interface.
I don't know why Apple did not include a placeHolder attribute on UITextView. But I was able to add one using a UILabel subview that contains the placeholder text.
Then show or hide it from delegate callbacks as below
- (void)textViewDidBeginEditing:(UITextView *)textView { self.defaultLabel.hidden = YES; } - (void)textViewDidChange:(UITextView *)txtView { self.defaultLabel.hidden = ([txtView.text length] > 0); } - (void)textViewDidEndEditing:(UITextView *)txtView { self.defaultLabel.hidden = ([txtView.text length] > 0); }
Why UITextField
has a placeholder value and UITextView
doesn't has nothing to do with with their inheritance, or even programming. It's about how Apple perceived their use and prefers their use.
UITextField
is a one line item. It can be used for entering usernames, passwords, address bits, or pretty much anything. Often you have several of them clumped together, and it might be hard to figure out which field should have which data without placeholder text. The place holder lets us know the purpose of the field.
UITextView
is a block of text. Usually several lines, which often have a header associated with them. As a result, placeholder text is often not useful. The text view is also more likely to be populated with static text which again, would make placeholder text not really useful.
Do I think Apple should add a placeholder property for UITextView
anyway? Yes. It's annoying to have to make my own on the occasion when I need it. Apple also uses placeholder text in some places where it uses a UITextView
. The following example is from adding a calendar entry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With