Creating custom text fields

I am starting IOS development and now I am creating a user registration form. However, the default textbox in xcode doesn't look pretty, please someone can tell me how to create a custom textbox like in Facebook app or Lynda app.

+3


source to share


4 answers


if you want to change to Storyboard

or xib

using

Attribute

enter image description here

The UITextField

property attribute is BorderStyle

set as None

you can adjust the width and height, no matter what you need, you can change

UITextBorderStyle

Property type as

UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect

      

If set UITextBorderStyleRoundedRect

, custom background images are ignored. Repeat the three steps that you can customize.



Additional apple Reference

programmatically

Objective-C

UITextField *txtEmailfield = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
txtEmailfield.font = [UIFont systemFontOfSize:15];
txtEmailfield.placeholder = @"Email(Required)";
txtEmailfield.autocorrectionType = UITextAutocorrectionTypeNo;
txtEmailfield.keyboardType = UIKeyboardTypeDefault;
txtEmailfield.returnKeyType = UIReturnKeyDone;
txtEmailfield.clearButtonMode = UITextFieldViewModeWhileEditing;
txtEmailfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
txtEmailfield.delegate = self;
txtEmailfield.borderStyle=UITextBorderStyleNone;
[self.view addSubview:txtEmailfield];

      

Swift

var txtEmailfield = UITextField(frame: CGRectMake(10.0, 20.0, 300.0,40.0))
txtEmailfield.backgroundColor = UIColor.redColor()
txtEmailfield.borderStyle = UITextBorderStyle.None
txtEmailfield.font=UIFont.systemFontOfSize(12)
txtEmailfield.placeholder="Email(Required)"
txtEmailfield.autocorrectionType=UITextAutocorrectionType.No
txtEmailfield.keyboardType=UIKeyboardType.Default
txtEmailfield.returnKeyType=UIReturnKeyType.Done
txtEmailfield.delegate = self
txtEmailfield.clearButtonMode=UITextFieldViewMode.WhileEditing
txtEmailfield.contentVerticalAlignment=UIControlContentVerticalAlignment.Center
self.view.addSubview(txtEmailfield)

      

+6


source


There are various properties in the UITextField class that you can use to customize the text field. for example a borderStyle property to customize the border, whether you want to round a rectangle or a line, etc. Follow the link below: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/



0


source


Create a subclass that inherits from UITextfield, then rewrite some methods or add some custom views to layoutsubviews. And you can check this page from apple to see what UITextfield is. https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/

0


source


If you just want to change the UI of the textField, you can do this in your storyboard or nib:

enter image description here

Notice the style of the border, the default is RoundRect (fourth). but if you want to customize the UI then select 1st (BorderStyle: None)

Now you can place the background image or change its color and text as you like.

0


source







All Articles