Add UITextField to title view of navigation item

£可爱£侵袭症+ 提交于 2019-12-22 03:47:02

问题


How do you add a text field to the title view of a navigation item and have it sized correctly?

It works fine if I do this with a search bar like this but I don't know how to get a text field to size itself in the same way as a search bar.

myViewController.navigationItem.titleView = [UISearchBar new];

回答1:


As my comment suggested, try the following, which seems to me is what you're after.

UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.width, 21.0)];

self.navigationItem.titleView = textField;

[textField becomeFirstResponder];


来源:https://stackoverflow.com/questions/24976109/add-uitextfield-to-title-view-of-navigation-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!