我是IOS開發新手。我在動態設置Tabbar項目的圖像時遇到了一個問題。我已經分類了UITabbarItem。如何在tabbar控制器支持iPhone中的所有方向時設置tabbar項目的圖像
@interface CustomTabBarItem : UITabBarItem
{
UIImage *customHighlightedImage;
UIImage *customStdImage;
}
@property (nonatomic, retain) UIImage *customHighlightedImage;
@property (nonatomic, retain) UIImage *customStdImage;
@end
並添加我的tabbarcontroller到窗口。
[_tabBarController setViewControllers: [[NSArray alloc] initWithObjects:1,2,3,4,nil] animated: YES];
_tabBarController.selectedIndex = 0;
_tabBarController.delegate = self;
_tabBarController.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"tabbarBackground.png"]];
[self.window addSubview:_tabBarController.view];
self.window.rootViewController = _tabBarController;
[self.window makeKeyAndVisible];
我的Tabbar控制器完全支持所有的方向。但問題是,當我旋轉設備時,如何爲設備的當前方向設置標籤欄項目的圖像。該框架會自動設置爲每個選項卡,但我的圖像不會。我的應用程序中有四個選項卡。我通過網站搜索了很多,但無法獲得適當的解決方案。
編輯
這是我用於設置圖像的代碼。
tabBarItemBrowse=[[CustomTabBarItem alloc] init];
tabBarItemBrowse.imageInsets=UIEdgeInsetsMake(6, 0, -6, 0);
// tabBarItemBrowse.customStdImage=[UIImage imageNamed:@"browser.png"];
// tabBarItemBrowse.customHighlightedImage=[UIImage imageNamed:@"browser_act.png"];
if ([UIApplication sharedApplication].statusBarOrientation==UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
tabBarItemBrowse.customStdImage=[UIImage imageNamed:@"browser.png"];
tabBarItemBrowse.customHighlightedImage=[UIImage imageNamed:@"browser_act.png"];
}
else
{
tabBarItemBrowse.customStdImage=[UIImage imageNamed:@"browser568.png"];
tabBarItemBrowse.customHighlightedImage=[UIImage imageNamed:@"browser_act568.png"];
}
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
BrowseNav = [[CustomNavigationControllerViewController alloc] initWithRootViewController:self.viewController];
BrowseNav.tabBarItem = tabBarItemBrowse;
BrowseNav.navigationBar.tintColor = [UIColor blackColor];
BrowseNav.navigationBarHidden=YES;
[tabBarItemBrowse release];
請使用您所設定的圖像 – Rajneesh071
檢查你的方位在所有視圖控制器 – Rajneesh071