UIToolbar精确尺寸
我正在尝试借助工具栏自定义我的导航栏。 我以编程方式实现了它,如下所示:
UIToolbar* tools = [[UIToolbar alloc] initWithFrame: CGRectMake(0, 0, 100, 44.01)];
然后将其添加到我的导航栏中。问题是我在边框上有这种丑陋的效果:
我尝试更改 y 和高度值,没有结果。 您有什么想法可以避免这种情况吗?
预先感谢,亚萨
I'm trying to customize my NavigationBar with the help of a toolbar.
I've implemented it programmatically as follows:
UIToolbar* tools = [[UIToolbar alloc] initWithFrame: CGRectMake(0, 0, 100, 44.01)];
and then I added it to my NavigationBar. The problem is that I have this ugly effect on the borders:
I've tried to change the y and the height values, with no results.
Do you have any ideas to avoid this?
Thanks in advance, yassa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不会这样做。
您可以通过向 navigationItem.rightBarButtonItem 添加带有 2 个按钮的视图来实现相同的效果。这很简单:
I wouldn't do it this way.
You can achieve the same effect by adding a view with 2 buttons to the navigationItem.rightBarButtonItem. it is very simple:
我部分同意之前的回答和评论。
您建议的解决方案适用于自定义按钮。但是如果我想实现标准的编辑按钮怎么办?
对标准按钮/图标的访问是通过 UIBarButtonItem 类,而不是 UIButton。并且您无法将 UIBarButtonItem 对象添加到 UIView。
经过在网上进行大量研究后,我找到了完全满足我的要求的解决方案。工具栏必须按以下方式创建:
这就是结果:
希望它有所帮助!
亚萨
I partially agree with previous answers and comments.
The solution you suggested works fine for custom buttons. But what if I want to implement standard Edit button?
Access to the standard buttons/icons is through the UIBarButtonItem class, not UIButton. And you can't add UIBarButtonItem objects to a UIView.
After many research on the web, I've found the solution that completely cover my requirement. The toolbar must be created in the following way:
And this is the result:
Hope it helps!
yassa
或者你也可以用这种方式来做。
只需像这样创建 UIToolbar 的新子类
并将其用作普通 UIToolbar 即可。我不知道为什么,但它确实有效。
Or you can do it in this way.
Just create new subclass of UIToolbar like this
And use it as normal UIToolbar. I don't know why but it just works.