Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Add Input Accessory View above UIKeyBoard in iOS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.06k
    Comment on it

    If you come across a requirement where you want to add a custom view just above the UIKeyBoard, then you can use below code to do that.

    If you want to show custom view on tapping inside any UITextField or UITextView, Write below line of code in their delegate methods. I am doing it for UITextView.

    - (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    [textView setInputAccessoryView:[self getTextFieldAccessoryView]];
    return YES;
    }
    

    Here is the method to create custom view:-

    -(UIView *)getTextFieldAccessoryView{
    //create your own custom view here...
    UIButton *cancel = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancel setFrame:CGRectMake(0, self.view.bounds.size.height+1, 320.0, 40.0)];
    [cancel setBackgroundImage:[UIImage imageNamed:@"yellow-button-bg"] forState:UIControlStateNormal];
    [cancel setTitle:@"Cancel" forState:UIControlStateNormal];
    [cancel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cancel addTarget:self action:@selector(cancelTapped) forControlEvents:UIControlEventTouchUpInside];
    return cancel;
    }
    
    
    -(void)cancelTapped{  //do whatever you want...
    [self.view endEditing:YES];
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: