将UITextField添加到导航项的标题视图 [英] Add UITextField to title view of navigation item

查看:66
本文介绍了将UITextField添加到导航项的标题视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在导航项的标题视图中添加文本字段,并调整其大小?

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];

推荐答案

正如我的评论所建议的,请尝试以下操作,在我看来,这就是您所追求的.

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];

这篇关于将UITextField添加到导航项的标题视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆