问题
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