在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