UITextField

来源:互联网 发布:java面对对象经典案例 编辑:程序博客网 时间:2024/05/22 06:40

code

圆角,有占位符

    UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 190, 30)];    myTextField.borderStyle = UITextBorderStyleRoundedRect;    myTextField.placeholder = @"这是占位符";    [self.view addSubview:myTextField];    [myTextField release];

按return回收键盘

-(BOOL) textFieldShouldReturn:(UITextField *) textField{    [textField resignFirstResponder];    return YES;}

防止键盘挡住文本框

-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField{    CGFloat h = textField.center.y - self.view.frame.size.height / 2;    if (h > 0) {        self.view.center = CGPointMake(self.view.center.x, self.view.center.y - h);    }    return YES;}- (BOOL) textFieldShouldEndEditing:(UITextField *)textField{//    self.view.frame = CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height);    CGFloat h = textField.center.y - self.view.frame.size.height / 2;    if (h > 0) {        self.view.center = CGPointMake(self.view.center.x, self.view.center.y + h);    }    return YES;}

property

  • borderStyle UITextBorderStyleRoundedRect圆形边框
  • layer.borderWidth
  • placeholder 占位符
  • secureTextEntry 密文输入
  • keyboardType 键盘显示样式
  • returnKeyType return按钮样式
  • clearButtonMode 一次性清除输入的内容
  • inputAccessoryView 辅助视图(键盘上面的视图)
  • inputView 弹出自定义视图,可以用来弹出自定义键盘

protocol

-(BOOL) textFieldShouldClear: 可实现撤销操作
-(BOOL) textFieldShouldReturn: 回收键盘
-(BOOL) textFieldShouldBeginEditing:
-(BOOL) textFieldShouldEndEditing:
-(BOOL)textField: shouldChangeCharactersInRange:replacementString
-(void) textFieldDidEndEditing:

0 0
原创粉丝点击