相关疑难解决方法(0)

添加按钮以隐藏键盘

在UITextView上隐藏键盘,有方法:

...
    textfield.returnKeyType = UIReturnKeyDone;
    textfield.delegate = self;
....

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

}
Run Code Online (Sandbox Code Playgroud)

但如果我想将"完成"按钮留给"返回"并添加一个按钮来隐藏键盘,我该怎么办?

keyboard cocoa-touch uitextview ios

14
推荐指数
2
解决办法
3万
查看次数

尝试将完成按钮添加到数字键盘

我正在尝试向UIKeyboadnumpad添加一个"完成"按钮,但没有成功.我的代码有什么问题?

键盘没有完成按钮

@implementation DemoViewController

- (void)loadView {
    self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];

    textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 26)];
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.keyboardType = UIKeyboardTypeNumberPad;
    textField.returnKeyType = UIReturnKeyDone;
    textField.textAlignment = UITextAlignmentLeft;
    textField.text = @"12345";
    [self.view addSubview:textField];

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(keyboardWillShow:) 
                                                 name:UIKeyboardWillShowNotification 
                                               object:nil];
}

- (void)keyboardWillShow:(NSNotification *)note {  
    // create custom button
    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
    [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
    [doneButton …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

ios ×2

cocoa-touch ×1

iphone ×1

keyboard ×1

objective-c ×1

uitextview ×1