Move UITabBar to the top of a UITabBarController?

旧城冷巷雨未停 提交于 2019-11-30 16:23:05

I think it can be done, but you should be aware of this:

"Important: In iPhone OS 3.0 and later, you should not attempt to use the methods and properties of this class to modify the tab bar when it is associated with a tab bar controller object. Modifying the tab bar in this way results in the throwing of an exception. Instead, any modifications to the tab bar or its items should occur through the tab bar controller interface. You may still directly modify a tab bar object that is not associated with a tab bar controller."

So, in your UI (I suppose you defined it in Interface Builder), instantiate a UITabBar object (by choosing it in the IB library and dragging it to your view in IB). Choose the default position and also define the way that this tab bar autoresizes (using the size pane of the info window). Then, add an outlet to your view controller of type UITabBar, and, finally, connect the tab bar object to the tab bar outlet.

Once you have done this, in your view controller's viewDidLoad method you can customize any property of the tab bar that you want to.

Hope the below code helps

UITabBarController *tabC = [[UITabBarController alloc]init];
    tabC.tabBar.frame = CGRectMake(0, 0, 320, 70);

    NSArray *arr = [[NSArray alloc]initWithObjects:firstObj,secObj, nil];

    tabC.viewControllers = arr;

    [self.window addSubview:tabC.view];

Worked fine for me

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