自定义 UITabBarItem 的图标位置和标题(iphone sdk)
我有一个 tabBar,我想自定义选项卡栏中的项目。我想阻止标题的显示(通过将标题设置为nil可以轻松实现),并将图标位置重置为中心垂直位置。有谁知道如何做到这一点?
谢谢。
I have a tabBar, and I want to customise the items in the tab bar. I want to prevent the display of the title (easily achieved by setting the title to nil), and reset the icon position to be in the central vertical position. Does anyone have any idea of how this can be done?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
丑陋的黑客“解决方案”:将顶部图像插图设置为正值,将底部插图设置为相等但负值。
Ugly hacky "solution": set top image inset to positive value, bottom inset to equal but negative value.
正如 MM 所说,使用项目的 imageInsets 属性:
tabBarItem.imageInsets = UIEdgeInsetsMake(offset, 0, -offset, 0);
As MM says, use the item's imageInsets property:
tabBarItem.imageInsets = UIEdgeInsetsMake(offset, 0, -offset, 0);
您可以尝试使用 UIToolBar 而不是 UITabBar。 UIBarButtonItem 有方法 initWithCustomView。这比较复杂,但可能会正常工作。
You can try to use UIToolBar instead of UITabBar. UIBarButtonItem has method initWithCustomView. This is more complicated but may work properly.