UITextField的使用

手指长时间按住TextField时会出现“粘贴”等东西,如果想去掉的话可以:

1、create一个新class继承 UITextField

2、在 .m文件中添加一个方法:

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {

    UIMenuController *menuController = [UIMenuController sharedMenuController];

    if (menuController) {

        [UIMenuController sharedMenuController].menuVisible = NO;

    }

    return NO;

}

数字键盘添加自定义按钮方法:
    UITextField *pwd = [[UITextField alloc]init];
    CGFloat pwdX = 50;
    CGFloat pwdY = 100;
    CGFloat pwdW = self.view.frame.size.width - pwdX * 2;
    CGFloat pwdH = 30;
    pwd.frame = CGRectMake(pwdX, pwdY, pwdW, pwdH);
    pwd.placeholder = @"请输入密码";
    pwd.keyboardType = UIKeyboardTypeNumberPad;
    pwd.borderStyle = UITextBorderStyleRoundedRect;
    self.textField = pwd;
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShowOnDelay:) name:UIKeyboardWillShowNotification object:nil];

- (void)keyboardWillShowOnDelay:(NSNotification *)notification
{
    [self performSelector:@selector(keyboardWillShow:) withObject:nil afterDelay:0];
}

- (void)keyboardWillShow:(NSNotification *)notification
{
    UIButton *doneButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 163, 106, 53)];
    [doneButton setTitleColor:PNBlack forState:UIControlStateNormal];
    [doneButton setTitle:@"完成" forState:(UIControlStateNormal)];
    [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
    UIWindow * tempWindow = [[[UIApplication sharedApplication]windows]objectAtIndex:1];
    UIView * keyBoard = nil;
    for (int i = 0; i < tempWindow.subviews.count; i ++) {
        keyBoard = [tempWindow.subviews objectAtIndex:i];
        
        [keyBoard addSubview:doneButton];
    }
    
}

#pragma mark -
- (void)doneButton:(UIButton *)btn{
    [self.textField resignFirstResponder];
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值