在UISearchBar左侧添加按钮 [英] Adding button to left of UISearchBar

查看:194
本文介绍了在UISearchBar左侧添加按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在把这头发撕掉。我的客户想要在搜索栏的左侧添加一个按钮,如下例所示:

I am tearing my hair out on this one. My client wants to add a button to the left of a search bar like the example below:

alt text http://www.erik.co.uk/images/IMG_0008.PNG

但我可以弄清楚该怎么做。 Apple似乎没有提供任何记录方法来向UISearchBar添加自定义按钮,更不用说在搜索栏的左侧。

But I just can't figure out how to do it. Apple don't seem to provide any documented method for adding custom buttons to a UISearchBar, let alone to the left of the search bar.

我已经尝试在Interface Builder中添加一个UIToolbar,左边有一个按钮,但我找不到任何两种风格的组合给人一种他们是一体的印象。从下图中可以看出,垂直对齐中总有一个像素差异:

I've tried hacking around in Interface Builder adding a UIToolbar with a button in it to the left but I cannot find any combination of styles where the two line up properly to give the impression that they are one. There is always what looks like one pixel difference in the vertical alignment as you can see from the picture below:

alt text http://www.erik.co.uk/images/verticalalignment.png

I已经四处寻找,但是找不到答案,但正如我们从截图中看到的那样,它必须是可能的!

I've searched around and just can't find the answer, but as we can see from the screenshot it must be possible!

提前感谢您的帮助。

Erik

推荐答案

使用导航栏而不是工具栏。将搜索栏设置为导航栏的标题视图。

Use a navigation bar instead of a toolbar. Set the search bar to the navigation bar's title view.

界面生成器

结果:

这篇关于在UISearchBar左侧添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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