Subclass of UITabBarController, replaced the TabBar and have a display issue

不问归期 提交于 2019-12-13 12:09:59

问题


I have an iPhone app which was built using a standard UITabBarController. This app was created using the standard XCode project template.

Now, I have a requirement to change the UITabBar to look very different. The approach I decided to take was like this:

in my AppDelegate:

for (UIView *view in tabBarController.view.subviews) {  
    if([view isKindOfClass:[UITabBar class]]) {
        view.hidden = YES;
        break;
    }
}

This works to make the tab bar hidden. Next, I subclassed UITabBarController and I add a UIToolbar with a few custom components. In my subclassed UITabBarController I have my code set up so that when one of my custom objects is selected, the code simply calls [self setSelectedIndex:n] to update the UI.

So I basically have a UITabBarController but I am controlling it through a new UI.

The problem is that my new components aren't quite as tall as the normal UITabBar and the UITabBarController seems to be not resizing my views automatically. I actually would expect this behavior, but I can't figure out how to change the "content frame" of a UITabBarController. Any ideas?


回答1:


  1. Check the autoresizingMask property.
  2. Are you expecting them to work as tab bars usually do by adding items to the viewControllers view?



回答2:


Resolved with the following code:

[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 436)];

(I know this code has issues btw and will come back to haunt me on the iPad or other devices).



来源:https://stackoverflow.com/questions/2078507/subclass-of-uitabbarcontroller-replaced-the-tabbar-and-have-a-display-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!