我是IOS开发的初学者,现在我正在创建一个用户注册表单。但是,xcode中默认的文本字段看起来并不漂亮,请任何人都可以告诉我如何在Facebook应用程序或Lynda应用程序中创建自定义文本字段。
答案 0 :(得分:8)
如果您想使用
更改Storyboard
或xib
<强>属性强>
在UITextField
属性属性BorderStyle
设置为None
,您可以自定义宽度和高度,无论您需要什么,都可以更改
UITextBorderStyle
属性类型为
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
如果设置为UITextBorderStyleRoundedRect
,则会忽略自定义背景图片。您可以自定义三件事。
编程
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];
<强>夫特强>
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)
答案 1 :(得分:0)
UITextField类中有各种属性可用于自定义文本字段。例如borderStyle属性来自定义边框是否要圆角矩形或直线等。 点击以下链接: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/
答案 2 :(得分:0)
创建一个继承自UITextfield的子类,然后重写一些方法或在layoutsubviews中添加一些自定义视图。你可以从苹果查看这个页面,看看UITextfield有什么。 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/
答案 3 :(得分:0)