手指长时间按住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];
}