在StackOverflow上搜索幾個問題後,我發現只有1個主要項目用於創建自定義UITabBar,名爲BCTabBarController
。它的描述說:實現不使用私有API的自定義UITabBarControl
定製210有幾個問題與使用標準的UITabBarController 包括:
這是太高,尤其是在橫向模式下
高度不匹配UIToolbar
它不能在不使用專用的API
儘管如此,我發現this strange project on GitHub與tutorial here,使用標準UITabBarController
在其實施UIButtons
爲每個選項卡,它的工作(奇怪的是,但它)。
我想知道,如果這是錯誤的創建自定義UITabBarController
與UIButtons
,而不是標籤和那會導致成?這樣做的實施看起來是這樣的:
- (void)viewDidAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self hideTabBar];
[self addCustomElements];
}
- (void)hideTabBar
{
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
view.hidden = YES;
break;
}
}
}
-(void)addCustomElements
{
// Initialise our two images
UIImage *btnImage = [UIImage imageNamed:@"NavBar_01.png"];
UIImage *btnImageSelected = [UIImage imageNamed:@"NavBar_01_s.png"];
self.btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button
btn1.frame = CGRectMake(0, 430, 80, 50); // Set the frame (size and position) of the button)
[btn1 setBackgroundImage:btnImage forState:UIControlStateNormal]; // Set the image for the normal state of the button
[btn1 setBackgroundImage:btnImageSelected forState:UIControlStateSelected]; // Set the image for the selected state of the button
btn1.backgroundColor = [UIColor yellowColor];
[btn1 setTag:0]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed.
[btn1 setSelected:true]; // Set this button as selected (we will select the others to false as we only want Tab 1 to be selected initially
在我的項目,我將使用的是iOS 5.1及以上,沒有故事板或XIBs。謝謝!
感謝您指點我正確的方向! – 2013-03-04 14:36:04