Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Providing *hint* in text field in ios 7 as edittext field in android

I am creating a feedback form in an ios7 application and want to place few UITextFields which contain hints in the respective UITextField for name, phone number, email address, etc. I am using xcode 5 and ios7 for programming and creating application without use of storyboard.

The hint property is available in android for edit text field, but I am unable to find any such property in UITextField in ios 7.

like image 857
Niranjan Balkrishna Prajapati Avatar asked Feb 25 '14 09:02

Niranjan Balkrishna Prajapati


People also ask

Which property is used in IOS to set hint?

placeholder = @"Your hint here."; If you are using a storyboard or XIB, this property can be edited there also.

How do you make a text field non editable in Swift?

Set the Boolean variable to false, which enables editing in the text field. When someone taps the Done button, isEditing becomes false. Set the Boolean variable to true, which disables editing in the text field.

What is UITextField?

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


1 Answers

Make use of the Placeholder text property.

Here's an example:

UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, 100, 50)];
textField.font = [UIFont fontWithName:@"Arial" size:20];
textField.placeholder = @"Your hint here.";

If you are using a storyboard or XIB, this property can be edited there also.

Also, if you want to use custom attributes for the placeholder, you can use the attributedPlaceholder property:

NSAttributedString *attribString = [[NSAttributedString alloc] initWithText:@"Your hint here." attributes:@{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:16.0]}];
textField.attributedPlaceholder = attribString;
like image 154
ZeMoon Avatar answered Oct 27 '22 01:10

ZeMoon