Move UITabBar to the top of a UITabBarController?

微笑、不失礼 提交于 2019-11-30 16:08:34

问题


I just finished designing a application that uses a top bar that toggles between three UIViewControllers. My first thought was to use a UITabBarController, since it works very simular.

However, the tabBar is at the bottom and in my PSD, it's at the top. Is there anyway I can change it? I see in the library I can drag in a UITabBar, but I don't know how to get it to change pages from there.

Please help! Coulton


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6633541/move-uitabbar-to-the-top-of-a-uitabbarcontroller

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