Goal C how to add a text box to the navigation bar

I am trying to add a text box to the navigation bar, but it does not appear in the simulator. I do this as follows inside viewdidload:

UITextView *textField = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 170, 44)]; self.navigationItem.titleView = textField; 

Any ideas?

Thanks!

+2
source share
1 answer

I did it this way. I know that you got to the answer uptil now but still it will help someone else, so it can be done as follows:

  -(void)viewWillAppear:(BOOL)animated { imgVw =[[UIImageView alloc]initWithFrame:CGRectMake(68, 7, 180, 28)]; [imgVw setImage:[UIImage imageNamed:@"textfieldBackground.png"]]; [self.navigationController.navigationBar addSubview:imgVw]; textfieldTxt = [[UITextField alloc]initWithFrame:CGRectMake(78, 11, 170, 25)]; textfieldTxt.backgroundColor = [UIColor clearColor]; [textfieldTxt setAutocorrectionType:UITextAutocorrectionTypeNo]; textfieldTxt.delegate = self; [self.navigationController.navigationBar addSubview:textfieldTxt]; } 

please do not forget to remove from the supervisor when viewdidunload

  - (void)viewDidUnload { [super viewDidUnload]; [textfieldTxt removeFromSuperview]; [imgVw removeFromSuperview]; } 

thanks

+3
source

Source: https://habr.com/ru/post/972908/


All Articles