Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why UITextview does not have placeholder property like UITextField [duplicate]

Tags:

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.

like image 444
Mahesh Peri Avatar asked Apr 08 '13 14:04

Mahesh Peri


People also ask

What is placeHolder in Swift?

The string that displays when there is no other text in the text field.

What is UITextField in swift?

An object that displays an editable text area in your interface.


2 Answers

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); } 
like image 57
sixthcent Avatar answered Nov 13 '22 14:11

sixthcent


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.

Text field example

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.

Text view example with placeholder

like image 41
DBD Avatar answered Nov 13 '22 16:11

DBD