Swift - 文本输入框(UITextField)的用法
来源:互联网 发布:淘宝客退款还算佣金吗 编辑:程序博客网 时间:2024/06/05 06:47
原文地址:http://hangge.com/blog/cache/detail_530.html 作者:yuhang
1,文本框的创建,有如下几个样式:UITextBorderStyle.None:无边框
UITextBorderStyle.Line:直线边框
UITextBorderStyle.RoundedRect:圆角矩形边框
UITextBorderStyle.Bezel:边线+阴影
1
2
3
4
var
textField =
UITextField
(frame:
CGRectMake
(10,160,200,30))
//设置边框样式为圆角矩形
textField.borderStyle =
UITextBorderStyle
.
RoundedRect
self
.view.addSubview(textField)
1
textField.placeholder=
"请输入用户名"
1
2
textField.adjustsFontSizeToFitWidth=
true
//当文字超出文本框宽度时,自动调整文字大小
textField.minimumFontSize=14
//最小可缩小的字号
1
2
3
4
5
6
7
8
9
/** 水平对齐 **/
textField.textAlignment =NSTextAlignment.
Right
//水平右对齐
textField.textAlignment =NSTextAlignment.
Center
//水平居中对齐
textField.textAlignment =NSTextAlignment.
Left
//水平左对齐
/** 垂直对齐 **/
textField.contentVerticalAlignment =
UIControlContentVerticalAlignment.
Top
//垂直向上对齐
textField.contentVerticalAlignment =UIControlContentVerticalAlignment.
Center
//垂直居中对齐
textField.contentVerticalAlignment =UIControlContentVerticalAlignment.
Bottom
//垂直向下对齐
1
textField.background=
UIImage
(named:
"background1"
);
1
2
3
textField.clearButtonMode=
UITextFieldViewMode
.
WhileEditing
//编辑时出现清除按钮
textField.clearButtonMode=
UITextFieldViewMode
.
UnlessEditing
//编辑时不出现,编辑后才出现清除按钮
textField.clearButtonMode=
UITextFieldViewMode
.
Always
//一直显示清除按钮
1
textField.becomeFirstResponder()
1
2
3
4
5
6
textField.returnKeyType =
UIReturnKeyType
.
Done
//表示完成输入
textField.returnKeyType =
UIReturnKeyType
.
Go
//表示完成输入,同时会跳到另一页
textField.returnKeyType =
UIReturnKeyType
.
Search
//表示搜索
textField.returnKeyType =
UIReturnKeyType
.
Join
//表示注册用户或添加数据
textField.returnKeyType =
UIReturnKeyType
.
Next
//表示继续下一步
textField.returnKeyType =
UIReturnKeyType
.
Send
//表示发送
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class
ViewController
:
UIViewController
,
UITextFieldDelegate
{
override
func
viewDidLoad() {
super
.viewDidLoad()
var
textField =
UITextField
(frame:
CGRectMake
(10,160,200,30))
//设置边框样式为圆角矩形
textField.borderStyle =
UITextBorderStyle
.
RoundedRect
textField.returnKeyType =
UIReturnKeyType
.
Done
textField.delegate=
self
self
.view.addSubview(textField)
}
func
textFieldShouldReturn(textField:
UITextField
) ->
Bool
{
//收起键盘
textField.resignFirstResponder()
//打印出文本框中的值
println
(textField.text)
return
true
;
}
}
0 0
- Swift - 文本输入框(UITextField)的用法
- Swift - 文本输入框(UITextField)的用法
- Swift - 文本输入框(UITextField)的用法
- Swift - 文本输入框(UITextField)的用法
- Swift - 文本输入框(UITextField)的用法
- Swift 开发: 文本输入框(UITextField)的用法
- ios UITextField 文本输入框的用法
- Swift - 文本输入框(UI TextField)的用法
- UITextField(文本输入框)
- 文本输入框UITextField
- UITextField/文本输入框
- UITextField文本输入框
- Swift UITextField(单行文本输入控件)
- UItextField 用法(swift)
- 判断UITextField文本输入框的输入长度
- IOS - 获取UITextField的输入文本
- UITextField、UITextView--文本输入框,以及文本输入域
- UITextField 文本输入筛选
- JAVA中的三种遍历方式
- 增强现实的解密游戏
- jsoup爬虫爬取网页
- Leetcode 第8题 判断一个整数是否为回文串
- MySQL基本分页查询方法及其优化
- Swift - 文本输入框(UITextField)的用法
- 【温故而知新】【4】Verilog序列检测
- 安卓开发中Handler消息传递机制
- bash基本语法
- poj 3352 Road Construction(双联通)
- HSSFWorkBooK 设置excel样式用法
- 我与大话设计模式之代码篇(一)-----简单工厂
- 1004. Counting Leaves (30)
- 从Mysql某一表中随机读取n条数据的SQL查询语句