在 iPad 应用程序中更改 UITabbarItems 的宽度和它们之间的边距
是否可以更改 UITabbar 中 UITabbarItem 的宽度以及 iPad 应用程序的每个 UITabbarItem 之间的边距?
问题是标准边距对于我的布局来说太大 - 客户希望选项卡更紧凑:/
或者我应该混乱 UIToolbar 来实现这个目标吗?
Is it possible to change the width of UITabbarItem in UITabbar and margins between each UITabbarItem for iPad Application?
The problem is that standard margins are too large for my layout - client want tabs to be more compact :/
Or should I mess with UIToolbar to achieve this goal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
对于选项卡栏项目宽度:
对于选项卡栏框架:
For Tabbar item width :
For tabbar frame :
我已经通过这种方式解决了同样的问题:
我的目标是使用设计师为我发送的图像来自定义选项卡栏。
我已经附加了项目的.png文件,初始化了UIImage *类型的相应变量,并使用UITabBarItem函数setFinishedSelectedImage:withFinishedUnselectedImage:设置UITabbarItem的活动/非活动状态的图像:
但是自定义的tabbarItems比设计器的图像小并被一个接一个地分配在屏幕中央:
2)为了解决这个问题,我添加了额外的 UITABBARITEMS - 在左侧在初始的右上角
3) 创建了 UITabBarItems 的相应出口:
.h 文件:
然后按照下面列出的顺序将出口附加到 UITabBarItems:
并已更正委托类中的 UITabbarDelegate 方法仅切换甜菜可见项目
.m 文件:
现在一切看起来都正常并且工作正常。
您可以使用相同的步骤通过添加其他项目和更正委托方法来自定义 UITabBarItems 之间的大小和间距。
I have solved just the same problem it this way:
my goal was to customize tab bar by using images, that were sent by the designer for me.
I have attached the .png files for the project, initialized the correspondent variables of type UIImage* and used UITabBarItem function setFinishedSelectedImage: withFinishedUnselectedImage: to set the images for active / inactive state of UITabbarItem:
But the customized tabbarItems were smaller, than the designer's images and were allocated at the center of the screen one upon other:
2) To fix this I have ADDED ADDITIONAL UITABBARITEMS - at the left and at the right corner of the initial ones
3) the were created the correspondent outlets for the UITabBarItems:
.h-file:
then attached the Outlets to the UITabBarItems in the order listed below:
and CORRECTED THE UITabbarDelegate METHOD in the delegating class to switch ONLY beet wen the visible items
.m-file:
Now everything looks and works properly.
You can use the same steps to customize the size and interspaces between UITabBarItems by adding additional items and correcting delegate methods.
我认为这是不可能的。您可以创建自定义选项卡栏。另外,弄乱默认的 UItabbar 可能会导致应用程序审批过程中被拒绝。
I don't think it is possible. You can create a custom tab bar. Also messing around with default UItabbar might cause rejection during App approval process.
您可以通过子类化 UITabBar 并重写其 layoutSubviews 方法来更改选项卡栏项目的间距。您将在 self.subViews 数组中找到所有选项卡栏按钮。它们的类是非公共的 UITabBarButton,但它们继承自 UIControl,因此您可以识别所有选项卡栏按钮,检查它们是否属于 UIControl 类。然后您所需要做的就是更改选项卡栏按钮的框架。
You can change the spacing of the tab bar items by subclassing UITabBar and overriding its layoutSubviews method. You will find all tab bar buttons in the self.subViews array. Their class is the non-public UITabBarButton but they inherit from UIControl so you can identify all tab bar buttons checking if they are kind of UIControl class. Then all you need is to change the frame of the tab bar buttons.
您可以使用 setSelectionIndicatorImage 使选项卡更加紧凑。
SelectionIndicatorImage 宽度匹配
iPad 中的 UITabBarItem 宽度将与AppDelegate.m 中的
,您可以使用下面的代码以编程方式创建图像
You can use setSelectionIndicatorImage to make your tab more compact.
The UITabBarItem width in iPad will match the selectionIndicatorImage's width
in AppDelegate.m
you can use below code to create a image programmatically
不需要子类化。
No subclassing is needed.
您无法更改
UITabBarItem
的宽度,即使在子类化 UITabBarItem 之后也无法执行此操作。苹果公司对开发者实施应用程序的方式有一定的限制。为此,您需要使用
UIToolBar
,我最好的选择是您转到github
,因为那里有很多使用可滚动 UIToolBar 的示例应用程序底部而不是UITabBar
。You cannot change the width of the the
UITabBarItem
, and you cannot do this even after subclassing the UITabBarItem. Apple has certain restrictions in the way they want the developers to implement the applications.You will need to use a
UIToolBar
for this, and my best bet is for you to go togithub
and as there a lot of sample applications which use a scrollable UIToolBar at the bottom instead of theUITabBar
.