UITextField

  //创建 
     UITextField*textfield = [[UITextField             alloc]initWithFrame:CGRectMake(20,20,200,40)];
    [self.window addSubview:self.myTextField];
   
    //设置背景颜色
    self.myTextField.backgroundColor = [UIColor clearColor];
   
    //设置输入框样式
    self.myTextField.borderStyle = UITextBorderStyleRoundedRect;
   
    //密文输入
    self.myTextField.secureTextEntry = YES;
   
    //设置占位提示符
    self.myTextField.placeholder = @"请输入";
   
    //设置输入框删除按钮
    self.myTextField.clearButtonMode = UITextFieldViewModeAlways;
   
    //设置键盘类型
    self.myTextField.keyboardType = UIKeyboardTypeNumberPad;


/******按按钮键盘隐藏*********************************/
  //创建按钮
    UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.window addSubview:Button];
    Button.frame = CGRectMake(20, 80, 100, 30);
    Button.backgroundColor = [UIColor cyanColor];

    [Button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

-(void) buttonAction:(UIButton *)b
{
    [self.myTextField resignFirstResponder];
    //取消第一响应者
}
/******************************************************/



/******按return键盘隐藏*********************************/
1.签UITextFieldDelegate协议
@interface AppDelegate : UIResponder <UIApplicationDelegate,UITextFieldDelegate>

2.成为代理人
哪个输入框成为代理人哪个输入框有此功能
 self.myTextField.delegate = self;

3.实现协议里的方法
//点击return建的时候被触发
通用,一个就可以给所有输入框用
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.myTextField resignFirstResponder];
    return YES;

}
/******************************************************/

/******按空白处键盘隐藏*********************************/
 //按空白处键盘回收
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(backgroundTap:)];
    [self.view addGestureRecognizer:tap];

//按空白处键盘回收调用的方法
- (IBAction)backgroundTap:(id)sender {
    [self.studentDetailV.tf1  resignFirstResponder];
    [self.studentDetailV.tf2  resignFirstResponder];
    [self.studentDetailV.tf3  resignFirstResponder];
    [self.studentDetailV.tf4  resignFirstResponder];
    [self.studentDetailV.tf5  resignFirstResponder];
   
}
/******************************************************/




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值