Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 奇怪的不均匀宽度?_Ios_Objective C_Uitabbarcontroller_Uitabbar_Uitabbaritem - Fatal编程技术网

Ios 奇怪的不均匀宽度?

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

我有一个带有4个选项卡的自定义
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倍)
此外,我还对App Delegate的
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
,我也不知道。很抱歉