UITextField

UITextField

创建输入框确定输入框的位置和大小

UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 40)];

输入框的背景颜色

textFiled.backgroundColor = [UIColor redColor];

输入框的边框宽 圆角 边框颜色

textFiled.layer.borderWidth = 1;
textFiled.layer.cornerRadius = 10;
textFiled.layer.borderColor = [UIColor blackColor].CGColor;

输入框内文本的颜色及对齐方式

textFiled.textColor = [UIColor yellowColor];
textFiled.textAlignment = NSTextAlignmentCenter;

占位文本 文本框内字体的大小

textFiled.placeholder = @"hey";
textFiled.font = [UIFont fontWithName:@"" size:20];

输入需要保密的文件时可以将字符设置成圆点

textFiled.secureTextEntry = YES;

设置不同类型的键盘

textFiled.keyboardType = UIKeyboardTypeNumberPad;

改变return的样式 这里指键盘的return按钮可设置成Done 等按钮

textFiled.returnKeyType = UIReturnKeySearch;

输入框中的清除按钮(就是输入框中的圆按钮) 及样式设置

textFiled.clearsOnBeginEditing = YES;
textFiled.clearButtonMode = UITextFieldViewModeAlways;

弹出自定义的视图

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100,200 , 200, 200)];
    view.backgroundColor = [UIColor redColor];
//弹出自定义视图.默认是键盘
textFiled.inputView = view;
//给键盘添加一个辅助视图
textFiled.inputAccessoryView = view;

键盘的回收需要签订协议才能在方法中实现

//签订协议
@interface AppDelegate ()<UITextFieldDelegate>
//设置代理人
textFiled.delegate = self;
//实现协议方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSLog(@"测试return按钮");
//这句话是实现回收键盘的关键
    [textField resignFirstResponder];
    return YES;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值