Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Custom Text Fields

I'm Beginner in IOS development, and now I'm creating a form for user registration. However the text field that is default in xcode doesn't look pretty please anyone can tell me how to make a custom text field such us in Facebook application or Lynda application.

like image 554
Ahmed jamal Avatar asked Aug 07 '15 08:08

Ahmed jamal


1 Answers

if you want to change in Storyboard or xib using

Attribute

enter image description here

In UITextField Attribute property has BorderStyle set as None , you can customize the width and height , whatever you need you can change

the UITextBorderStyle Property type as

UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect

If set to UITextBorderStyleRoundedRect, custom background images are ignored.else three things 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)
like image 164
Anbu.Karthik Avatar answered Oct 06 '22 19:10

Anbu.Karthik