Ios 奇怪的不均匀宽度?
我有一个带有4个选项卡的自定义Ios 奇怪的不均匀宽度?,ios,objective-c,uitabbarcontroller,uitabbar,uitabbaritem,Ios,Objective C,Uitabbarcontroller,Uitabbar,Uitabbaritem,我有一个带有4个选项卡的自定义UITabBarController。子类代码如下所示: - (void)viewDidLoad { [super viewDidLoad]; [self.viewControllers enumerateObjectsUsingBlock:^(UIViewController *vc, NSUInteger idx, BOOL *stop) { NSLog(@"Tab %d: %.1f", (int)idx, vc.tabBarIt
UITabBarController
。子类代码如下所示:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.viewControllers enumerateObjectsUsingBlock:^(UIViewController *vc, NSUInteger idx, BOOL *stop) {
NSLog(@"Tab %d: %.1f", (int)idx, vc.tabBarItem.image.size.width);
}];
}
- (void)viewWillLayoutSubviews {
CGRect tabFrame = self.tabBar.frame;
tabFrame.size.height = 56;
NSLog(@"Width: %.1f", tabFrame.size.width);
NSLog(@"Screen Width: %.1f", [[UIScreen mainScreen] bounds].size.width);
tabFrame.origin.y = self.view.frame.size.height - 56;
self.tabBar.frame = tabFrame;
}
子类UITabBarController
将选项卡栏的高度增加到56像素。我在故事板上设置了班级
在故事板中,我还为选项卡设置了未选中的图像和选中的图像。图像大小为:
- 104 x 72像素(1x)
- 208x144px(2x)
- 311 x 215px(3倍)
didfishlaunchingwithoptions进行了一些调整:
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UITabBar appearance] setItemWidth:[[UIScreen mainScreen] bounds].size.width / 4];
但是,选项卡栏项的宽度略有不同。中间两个稍宽一些
然后,我使用NSLog
调试宽度。我发现标签宽度都报告为104.00,这是预期的
将选项卡调整回相等宽度时,我错过了什么?您是否尝试在“viewDidLayoutSubviews”中记录大小?如果我没记错的话,在viewdlayoutsubviews
中的“viewWillLayoutSubviews”之后会发生自动布局,我会像在viewdiload
中一样记录它。结果也是104.0
,我也不知道。很抱歉