在此先感謝。 我想添加兩個頂部和另一個底部的標籤欄控制器,如 這個。在iphone中可能嗎?如果可能,任何人都知道請幫助我做到這一點。與iphone中的tabbar控件相關的問題
0
A
回答
0
據我所知,應該可以做到這一點。只需添加一個到你的視圖,另一個添加到你的rootview控制器,在不同的位置,你應該能夠鏈接到不同的地方。如果沒有,只需拉起photoshop,「製作」標籤欄並將按鈕放在它下面以模擬效果。
PS,薩曼莎太美了!哈哈
0
UITabBar難以在任何方向上修改。
許多easyer將被你自己的,自定義的替換它。 Offcorse,它可以是任何你喜歡的。看看這個:
//CustomTabBar.h:
#import <Foundation/Foundation.h>
@interface CustomTabBar : UITabBarController {
UIButton *SHOPPING;
UIButton *DINING;
UIButton *MAPS;
UIButton *PARKING;
UIButton *PROMOTION;
UIImageView *BarBackground;
}
-(void) addCustomElements;
-(void) hideExistingTabBar;
-(void) selectTab:(int)tabID;
@end
//CustomTabBar.m:
#import "CustomTabBar.h"
@implementation CustomTabBar
- (void)viewDidAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self hideExistingTabBar];
[self addCustomElements];
}
- (void)hideExistingTabBar
{
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
view.hidden = YES;
break;
}
}
}
- (void)dealloc {
[super dealloc];
}
-(void)addCustomElements
{
//in your case you will need 2 bars, but I needed only one. Just add another one.
BarBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BarBackground.jpg"]];
BarBackground.frame = CGRectMake(0, 430, 320, 50);
// Initialise our two images
UIImage *btnImage = [UIImage imageNamed:@"BarShipping.png"];
UIImage *btnImageSelected = [UIImage imageNamed:@"BarShipping.png"];
SHOPPING = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button
SHOPPING.frame = CGRectMake(0, 430, 64, 50); // Set the frame (size and position) of the button)
[SHOPPING setBackgroundImage:btnImage forState:UIControlStateNormal]; // Set the image for the normal state of the button
[SHOPPING setBackgroundImage:btnImageSelected forState:UIControlStateSelected]; // Set the image for the selected state of the button
[SHOPPING setTag:0]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed.
[SHOPPING setSelected:true]; // Set this button as selected (we will select the others to false as we only want Tab 1 to be selected initially
// Now we repeat the process for the other buttons
btnImage = [UIImage imageNamed:@"BarDinning.png"];
btnImageSelected = [UIImage imageNamed:@"BarDinning.png"];
DINING = [UIButton buttonWithType:UIButtonTypeCustom];
DINING.frame = CGRectMake(64, 430, 64, 50);
[DINING setBackgroundImage:btnImage forState:UIControlStateNormal];
[DINING setBackgroundImage:btnImageSelected forState:UIControlStateSelected];
[DINING setTag:1];
<...>
// Add my new buttons to the view
[self.view addSubview:BarBackground];
[self.view addSubview:SHOPPING];
[self.view addSubview:DINING];
<...>
// Setup event handlers so that the buttonClicked method will respond to the touch up inside event.
[SHOPPING addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[DINING addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
<...>
}
- (void)selectTab:(int)tabID
{
//if you will need navigation controller, or something, you will need to work on this part, or it will just crash.
switch(tabID)
{
case 0:
[SHOPPING setSelected:true];
[DINING setSelected:false];
<...>
break;
case 1:
[SHOPPING setSelected:false];
[DINING setSelected:true];
<...>
break;
<...>
}
if (self.selectedIndex == tabID) {
UINavigationController *navController = (UINavigationController *)[self selectedViewController];
[navController popToRootViewControllerAnimated:YES];
} else {
self.selectedIndex = tabID;
}
}
- (void)buttonClicked:(id)sender
{
int tagNum = [sender tag];
[self selectTab:tagNum];
}
@end
然後,像往常一樣添加和使用TabBarController。你必須做的唯一的事情就是將TabBarController類改爲這個,在你的xib文件中使用CastomTabBar。 (或者用這個類來分配它,如果你添加了它,那麼你的視圖就會被調整大小):UITabBarController * tb = [[CustomTabBar alloc] init];) 還有一個地方,那就是tabBar。如果你使用這個代碼,它將會是,但在平常的tabBar位置 - 在底部。對於第二個tabBar,你需要準備好自己的位置。希望,這會有所幫助。
相關問題
- 1. 與iPhone中的iAd相關的問題
- 2. iPhone:有關隱藏TabBar控制器的問題?
- 3. iPhone:有關隱藏TabBar控制器的問題?
- 4. 關於iphone中的tabBar控制器
- 5. iPhone的Tabbar +查看問題
- 6. 關於iPad/iPhone控件的問題
- 7. WinForms中承載的與WPF控件相關的性能問題
- 8. iphone中的導航相關問題
- 9. 與iPhone中的顏色相關的問題
- 10. 與@property相關的問題
- 11. 與IndexOutOfRangeException相關的問題
- 12. 與UIButton相關的問題
- 13. 與UITextView相關的問題
- 14. 與NSURLConnection相關的問題
- 15. 與jquery相關的問題
- 16. 與UNUserNotificationSettings相關的問題
- 17. 與JComboBox相關的問題
- 18. 與app_controller相關的問題
- 19. 與GoToStateAction相關的問題
- 20. 與UITabelViewCell相關的問題
- 21. 與errno.h相關的問題
- 22. 與mongodb相關的問題
- 23. 與mysqli_free_results相關的問題
- 24. 與getElementByTagName相關的問題
- 25. 與os.popen相關的問題
- 26. 與errno.h相關的問題
- 27. 與文件輸入相關的問題
- 28. 與C++相關的問題有問題
- 29. TabBar控制器問題
- 30. 與自定義控件相關的問題
我想這是不可能的,你需要自定義標籤欄。 – iOSPawan