【问题标题】:Resizing UISearchBar in UINavigation Bar?在导航栏中调整搜索栏的大小?
【发布时间】:2015-12-10 06:40:44
【问题描述】:

我已将 UISearchBar 添加到 UINavigationBar 并且效果非常好,除了此处 UISerachBar 的左侧填充。 在调试时,我知道这里的后退按钮框架太大,这就是 UINavigation 栏标题视图从左侧移动太多的原因。 怎么处理?

我想实现类似 twitter 应用程序,其中后退按钮和搜索栏之间的间距不大。

提前致谢!

【问题讨论】:

  • 你是将搜索栏添加为titleView还是rightView?

标签: ios objective-c iphone ios8 uisearchbar


【解决方案1】:

您可以在导航栏中添加自定义后退按钮来覆盖默认的后退按钮(在本例中为左按钮):

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my-back-button-image.png"]];
imageView.frame = CGRectMake(0, 0, 43, 30);

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:imageView];

self.navigationItem.leftBarButtonItem = barButtonItem;

左键和搜索控制器之间的距离变小了。

【讨论】:

    【解决方案2】:

    正如 Michele Broggi 之前提到的,您可以尝试一下。

    否则

    您还可以设置搜索栏来代替导航标题视图,使其与屏幕居中对齐(如果您想要那种设计)

    【讨论】:

      猜你喜欢
      • 2018-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多