Creating custom text fields
if you want to change to Storyboard
or xib
using
Attribute
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)
source to share
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/
source to share
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/
source to share
If you just want to change the UI of the textField, you can do this in your storyboard or nib:
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.
source to share