How to add separator between tabbar icon - objective-c

How to add a separator line between each icon for TabBar.
//TabbarViewController.h
#import <UIKit/UIKit.h>
#interface TabBarViewController : UITabBarController <UITabBarControllerDelegate>{ }
#end
//TabbarViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
HomeViewController *HomeViewController = [[HomeViewController alloc] init];
UploadViewController *UploadViewController = [[UploadViewController alloc] init];
MapViewController *mapviewController = [[MapViewController alloc]init];
FavouriteViewController *favouriteViewController = [[FavouriteViewController alloc]init];
HomeViewController.title = #"Home";
UploadViewController.title = #"Upload";
mapviewController.title = #"Map";
favouriteViewController.title = #"Favourite";
UINavigationController *homeNavCont = [[UINavigationController alloc] initWithRootViewController:HomeViewController];
UINavigationController *secondNavCont = [[UINavigationController alloc] initWithRootViewController:UploadViewController];
UINavigationController *thirdNavCont = [[UINavigationController alloc] initWithRootViewController:mapviewController];
UINavigationController *fourthNavCont = [[UINavigationController alloc] initWithRootViewController:favouriteViewController];
[[homeNavCont tabBarItem] setImage:[UIImage imageNamed:#“Home32”]];
[[secondNavCont tabBarItem] setImage:[UIImage imageNamed:#"camera32"]];
[[thirdNavCont tabBarItem] setImage:[UIImage imageNamed:#"Navigation32"]];
[[fourthNavCont tabBarItem] setImage:[UIImage imageNamed:#"Faviourte32"]];
HomeViewController.tabBarItem.selectedImage = [[UIImage imageNamed:#"Home32"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
UploadViewController.tabBarItem.selectedImage = [[UIImage imageNamed:#"camera32"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
mapviewController.tabBarItem.selectedImage = [[UIImage imageNamed:#"Navigation32"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
favouriteViewController.tabBarItem.selectedImage = [[UIImage imageNamed:#"Faviourte32"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
self.viewControllers=[NSArray arrayWithObjects:homeNavCont,secondNavCont,thirdNavCont,fourthNavCont,nil];
self.delegate = self;
[self setSelectedIndex:0];
}
Need your advice for adding separator in between icons for tabbar.

Related

TabBar with center button

Hi, I'd like to make a tabBar with center button. As we can see from the image, when I clicked the tabbar, it will show me a view to select buttons. When I clicked the "notes" button, the view will disappear and my app will jump to the correspond viewcontroller and the tabbar.selectIndex = 2. I already made a subclass of UITabBarController, and add a button to the view, the code is like this [self.view addSubview:middleButton]. Now the problem is, when I push viewcontroll, the tabbar disappear while the center button still on the page. And when I go back to the main viewcontroller, the tabbar will overlap the center button. I don't want to make a whole custom UITabBarViewController, please tell me how to hide the center button when push viewcontroll and how to show it on the tapbar when I go back to the main viewcontroller.
Hi, Hament, I have not use method "-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item". My code is as below:
#implementation MyTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupViews];
[self setupTabBarItems];
[self setupMiddleButton];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setupViews
{
mask = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([MyMiddleButtonMask class]) owner:self options:nil].firstObject;
mask.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
mask.delegate = self;
}
-(void)setupTabBarItems
{
UIViewController *vc1 = [[UIViewController alloc] init];
vc1Nav = [[UINavigationController alloc] initWithRootViewController:vc1];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2Nav = [[UINavigationController alloc] initWithRootViewController:vc2];
UIViewController *vc3 = [[UIViewController alloc] init];
vc3Nav = [[UINavigationController alloc] initWithRootViewController:vc3];
UIViewController *vc6 = [[UIViewController alloc] init];
vc6Nav = [[UINavigationController alloc] initWithRootViewController:vc6];
UIViewController *vc7 = [[UIViewController alloc] init];
vc7Nav = [[UINavigationController alloc] initWithRootViewController:vc7];
self.viewControllers = #[vc1Nav, vc2Nav, vc3Nav, vc6Nav, vc7Nav];
}
-(void)setupMiddleButton
{
middleButton = [[UIButton alloc] initWithFrame:CGRectMake(0, -16, 64, 64)];
CGRect f = middleButton.frame;
f.origin.y = SCREEN_HEIGHT - f.size.height;
f.origin.x = (SCREEN_WIDTH - f.size.width)/2;
middleButton.frame = f;
[middleButton setImage:[UIImage imageNamed:#"plus"] forState:UIControlStateNormal];
middleButton.backgroundColor = [UIColor redColor];
middleButton.layer.cornerRadius = middleButton.frame.size.height/2;
[self.view addSubview:middleButton];
[middleButton addTarget:self action:#selector(didClickedMiddleButton:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)didClickedMiddleButton:(id)sender
{
[[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:mask];
}
#pragma mark - KGOMiddleButtonMaskDelegate, Button1,2,3 are on the mask page.
-(void)didClickedButton1:(KGOMiddleButtonMask *)maskView
{
self.viewControllers = #[vc1Nav, vc2Nav, vc3Nav, vc6Nav, vc7Nav];
self.selectedIndex = 2;
[maskView removeFromSuperview];
}
-(void)didClickedButton2:(KGOMiddleButtonMask *)maskView
{
self.viewControllers = #[vc1Nav, vc2Nav, vc4Nav, vc6Nav, vc7Nav];
self.selectedIndex = 2;
[maskView removeFromSuperview];
}
-(void)didClickedButton3:(KGOMiddleButtonMask *)maskView
{
self.viewControllers = #[vc1Nav, vc2Nav, vc5Nav, vc6Nav, vc7Nav];
self.selectedIndex = 2;
[maskView removeFromSuperview];
}
-(void)didClickedSelf:(KGOMiddleButtonMask *)maskView
{
[maskView removeFromSuperview];
}
-(void)didClickedCloseButton:(KGOMiddleButtonMask *)maskView
{
[maskView removeFromSuperview];
}

Full width UITabbarcontroler for ipad

I have added UITabbarcontroller with 4 tabs on iPad . but in Ipad The tabs are not starting for x=0 its starting from middle.
How we can set the Uitabbar to use full width (768) of ipad so that all 4 tabs fits in full screen width
-(void) CreateTabBar
{
NSString *nibFile =#"";
NSString *imageType =#"";
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
nibFile = #"_iPhone";
imageType = #"";
}
else{
nibFile = #"_iPad";
imageType = #"_iPad";
}
SCViewController *bookCabView = [[SCViewController alloc] init];
UINavigationController *bookCabNavView = [[UINavigationController alloc]initWithRootViewController:bookCabView];
bookCabNavView.tabBarItem.image = [UIImage imageNamed:#"bookacab.png"];
// NSString *orderViewnibFile = #"";
NSString *serviceViewnibFile = #"";
NSString *contactusViewnibFile = #"";
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//orderViewnibFile = #"EXTableViewController_iPhone";
serviceViewnibFile = #"ServiceViewController_iPhone";
contactusViewnibFile = #"ContactUsViewController_iPhone";
}
else{
// orderViewnibFile = #"EXTableViewController_iPad";
serviceViewnibFile = #"ServiceViewController_iPad";
contactusViewnibFile = #"ContactUsViewController_iPad";
}
EXTableViewController *orderView = [[EXTableViewController alloc] init];
UINavigationController *orderCabNavView = [[UINavigationController alloc]initWithRootViewController:orderView];
orderCabNavView.tabBarItem.image = [UIImage imageNamed:[#"orders" stringByAppendingFormat:#"%#.png",imageType]];
ServiceViewController *serviceView = [[ServiceViewController alloc] initWithNibName:serviceViewnibFile bundle:nil];
UINavigationController *serviceNavView = [[UINavigationController alloc]initWithRootViewController:serviceView];
serviceNavView.tabBarItem.image = [UIImage imageNamed:[#"services" stringByAppendingFormat:#"%#.png",imageType]] ;
ContactUsViewController *contactusView = [[ContactUsViewController alloc] initWithNibName:contactusViewnibFile bundle:nil];
UINavigationController *contactNavView = [[UINavigationController alloc]initWithRootViewController:contactusView];
contactNavView.tabBarItem.image = [UIImage imageNamed:[#"contactus" stringByAppendingFormat:#"%#.png",imageType]];
UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTitle:#"" image:[UIImage imageNamed:#""] tag:1];
tab1.imageInsets = UIEdgeInsetsMake(0, 0, -15, 0);
[bookCabNavView setTabBarItem:tab1];
UITabBarItem *tab2 = [[UITabBarItem alloc] initWithTitle:#"" image:[UIImage imageNamed:#""] tag:2];
tab2.imageInsets = UIEdgeInsetsMake(0, 0, -15, 0);
[orderCabNavView setTabBarItem:tab2];
UITabBarItem *tab3 = [[UITabBarItem alloc] initWithTitle:#"" image:[UIImage imageNamed:#""] tag:3];
tab3.imageInsets = UIEdgeInsetsMake(0, 0, -15, 0);
[serviceNavView setTabBarItem:tab3];
UITabBarItem *tab4 = [[UITabBarItem alloc] initWithTitle:#"" image:[UIImage imageNamed:#""] tag:4];
tab4.imageInsets = UIEdgeInsetsMake(0, 0, -15,0);
[contactNavView setTabBarItem:tab4];
_tabBarCon = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
NSLog(#"%#",[#"bookacabhover" stringByAppendingFormat:#"%#.png",imageType]);
[tab1 setFinishedSelectedImage:[UIImage imageNamed:[#"bookacabhover" stringByAppendingFormat:#"%#.png",imageType]] withFinishedUnselectedImage:[UIImage imageNamed:[#"bookacab" stringByAppendingFormat:#"%#.png",imageType]]];
[tab2 setFinishedSelectedImage:[UIImage imageNamed:[#"ordershover" stringByAppendingFormat:#"%#.png",imageType]]withFinishedUnselectedImage:[UIImage imageNamed:[#"orders" stringByAppendingFormat:#"%#.png",imageType]]];
[tab3 setFinishedSelectedImage:[UIImage imageNamed:[#"serviceshover" stringByAppendingFormat:#"%#.png",imageType ]] withFinishedUnselectedImage:[UIImage imageNamed:[#"services" stringByAppendingFormat:#"%#.png",imageType ]]];
[tab4 setFinishedSelectedImage:[UIImage imageNamed:[#"contactsushover" stringByAppendingFormat:#"%#.png",imageType]] withFinishedUnselectedImage:[UIImage imageNamed:[#"contactus" stringByAppendingFormat:#"%#.png",imageType ]]];
_tabBarCon.viewControllers = [NSArray arrayWithObjects:bookCabNavView,
orderCabNavView,
serviceNavView,
contactNavView, nil];
_tabBarCon.delegate = self;
[self.view addSubview:_tabBarCon.view];
}

UItabBar from second view controller but all viewController have UInavigation with back to firstViewController issue

Let me explain my application first. I have six view controller
MenuViewController
FirstViewController
SecondViewController
ThirdViewController
FourthViewController
FifthViewController
All these 6 ViewControllers are in navigationController. I want to show my "MenuViewController" first at the starting time of the app, after splash screen, which contains 5 buttons (For :FirstViewController, SecondViewController, ThirdViewController, FourthViewController, FifthViewController). In this viewController there will be no TabBarController at the bottom of the page. But other viewController will be in tabbarController. When i touch one of those five button in menuviewController, it will bring me to that corresponding view controller where i can find the tabbarController at the bottom. I can do it with custom coding, positioning and setting image behind them. Here is the code:
AppDelegate.h :
#interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
{
UIImageView *firstTabImageView;
UIImageView *secondTabImageView;
UIImageView *thirdTabImageView;
UIImageView *fourthTabImageView;
UIImageView *fifthTabImageView;
UIImage *firstTabImage;
UIImage *firstTabActiveImage;
UIImage *secondTabImage;
UIImage *secondTabActiveImage;
UIImage *thirdTabImage;
UIImage *thirdTabActiveImage;
UIImage *fourthTabImage;
UIImage *fourthTabActiveImage;
UIImage *fifthTabImage;
UIImage *fifthTabActiveImage;
}
#property (strong, nonatomic) MenuViewController *menuViewController;
#property (strong, nonatomic) UINavigationController *navigationController;
#property (retain, nonatomic) IBOutlet UITabBarController *tabBarController;
AppDelegate.m :
-(void)makeTabBar
{
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
FirstViewController *firstViewController =[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
firstNavigationController.tabBarController.tabBar.tag = 0;
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
secondNavigationController.tabBarController.tabBar.tag = 1;
ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
UINavigationController *thirdNavigationController = [[UINavigationController alloc] initWithRootViewController:thirdViewController];
thirdNavigationController.tabBarController.tabBar.tag = 2;
FourthViewController *fourthViewController = [[FourthViewController alloc] initWithNibName:#"FourthViewController" bundle:nil];
UINavigationController *fourthNavigationController = [[UINavigationController alloc] initWithRootViewController:fourthViewController];
fourthNavigationController.tabBarController.tabBar.tag = 3;
FifthViewController *fifthViewController = [[FifthViewController alloc] initWithNibName:#"FifthViewController" bundle:nil];
UINavigationController *fifthNavigationController = [[UINavigationController alloc] initWithRootViewController:fifthViewController];
fifthNavigationController.tabBarController.tabBar.tag = 4;
menuNavigationController.navigationBarHidden = YES;
firstNavigationController.navigationBarHidden = YES;
secondNavigationController.navigationBarHidden = YES;
thirdNavigationController.navigationBarHidden = YES;
fourthNavigationController.navigationBarHidden = YES;
fifthNavigationController.navigationBarHidden = YES;
NSArray *viewControllers =[[NSArray alloc]initWithObjects:
firstNavigationController,
secondNavigationController,
thirdNavigationController,
fourthNavigationController,
fifthNavigationController,
nil];
firstTabImage = [UIImage imageNamed:#"MenuTabImage.png"];
firstTabActiveImage = [UIImage imageNamed:#"MenuTabImage_Active.png"];
secondTabImage = [UIImage imageNamed:#"TVGuideTabImage.png"];
secondTabActiveImage = [UIImage imageNamed:#"TVGuideTabImage_Active.png"];
thirdTabImage = [UIImage imageNamed:#"FirstRankTabImage.png"];
thirdTabActiveImage = [UIImage imageNamed:#"FirstRankTabImage_Active.png"];
fourthTabImage = [UIImage imageNamed:#"FavoriteTabImage.png"];
fourthTabActiveImage = [UIImage imageNamed:#"FavoriteTabImage_Active.png"];
fifthTabImage = [UIImage imageNamed:#"RegistrationTabImage.png"];
fifthTabActiveImage = [UIImage imageNamed:#"RegistrationTabImage_Active.png"];
CGRect frame = CGRectMake(0, 0, 320, 52);
UIView *viewa = [[UIView alloc] initWithFrame:frame];
UIImage *tabBarBackgroundImage = [UIImage imageNamed:#"Tab_Back.png"];
UIColor *color = [[UIColor alloc] initWithPatternImage:tabBarBackgroundImage];
[viewa setBackgroundColor:color];
if(IS_IPHONE_5)
{
[[self.tabBarController tabBar] insertSubview:viewa atIndex:1];
firstTabImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 519, 64, 49)];
secondTabImageView = [[UIImageView alloc]initWithFrame:CGRectMake(64, 519,64, 49)];
thirdTabImageView = [[UIImageView alloc]initWithFrame:CGRectMake(128, 519,64, 49)];
fourthTabImageView = [[UIImageView alloc]initWithFrame:CGRectMake(192, 519, 64, 49)];
fifthTabImageView = [[UIImageView alloc]initWithFrame:CGRectMake(256, 519, 64, 49)];
}
else
{
[[self.tabBarController tabBar] insertSubview:viewa atIndex:0];
firstTabImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 431, 64, 49)];
secondTabImageView = [[UIImageView alloc]initWithFrame:CGRectMake(64, 431,64, 49)];
thirdTabImageView = [[UIImageView alloc]initWithFrame:CGRectMake(128, 431,64, 49)];
fourthTabImageView = [[UIImageView alloc]initWithFrame:CGRectMake(192, 431, 64, 49)];
fifthTabImageView = [[UIImageView alloc]initWithFrame:CGRectMake(256, 431, 64, 49)];
}
firstTabImageView.image = firstTabActiveImage;
secondTabImageView.image = secondTabImage;
thirdTabImageView.image = thirdTabImage;
fourthTabImageView.image = fourthTabImage;
fifthTabImageView.image = fifthTabImage;
[self.tabBarController.view addSubview:firstTabImageView];
[self.tabBarController.view addSubview:secondTabImageView];
[self.tabBarController.view addSubview:thirdTabImageView];
[self.tabBarController.view addSubview:fourthTabImageView];
[self.tabBarController.view addSubview:fifthTabImageView];
self.tabBarController.delegate=self;
self.tabBarController.selectedIndex=0;
[tabBarController setViewControllers:viewControllers animated:NO];
}
- (void)tabBarController:(UITabBarController *)tabBarController1 didSelectViewController:(UIViewController *)viewController1
{
if (viewController1 == [tabBarController1.viewControllers objectAtIndex:0])
{
firstTabImageView.image = [UIImage imageNamed:#"MenuTabImage_Active.png"];
secondTabImageView.image = [UIImage imageNamed:#"TVGuideTabImage.png"];
thirdTabImageView.image = [UIImage imageNamed:#"FirstRankTabImage.png"];
fourthTabImageView.image = [UIImage imageNamed:#"FavoriteTabImage.png"];
fifthTabImageView.image = [UIImage imageNamed:#"RegistrationTabImage.png"];
}
else if (viewController1 == [tabBarController1.viewControllers objectAtIndex:1])
{
firstTabImageView.image = [UIImage imageNamed:#"MenuTabImage.png"];
secondTabImageView.image = [UIImage imageNamed:#"TVGuideTabImage_Active.png"];
thirdTabImageView.image = [UIImage imageNamed:#"FirstRankTabImage.png"];
fourthTabImageView.image = [UIImage imageNamed:#"FavoriteTabImage.png"];
fifthTabImageView.image = [UIImage imageNamed:#"RegistrationTabImage.png"];
}
else if (viewController1 == [tabBarController1.viewControllers objectAtIndex:2])
{
firstTabImageView.image = [UIImage imageNamed:#"MenuTabImage.png"];
secondTabImageView.image = [UIImage imageNamed:#"TVGuideTabImage.png"];
thirdTabImageView.image = [UIImage imageNamed:#"FirstRankTabImage_Active.png"];
fourthTabImageView.image = [UIImage imageNamed:#"FavoriteTabImage.png"];
fifthTabImageView.image = [UIImage imageNamed:#"RegistrationTabImage.png"];
}
else if (viewController1 == [tabBarController1.viewControllers objectAtIndex:3])
{
firstTabImageView.image = [UIImage imageNamed:#"MenuTabImage.png"];
secondTabImageView.image = [UIImage imageNamed:#"TVGuideTabImage.png"];
thirdTabImageView.image = [UIImage imageNamed:#"FirstRankTabImage.png"];
fourthTabImageView.image = [UIImage imageNamed:#"FavoriteTabImage_Active.png"];
fifthTabImageView.image = [UIImage imageNamed:#"RegistrationTabImage.png"];
}
else if (viewController1 == [tabBarController1.viewControllers objectAtIndex:4])
{
firstTabImageView.image = [UIImage imageNamed:#"MenuTabImage.png"];
secondTabImageView.image = [UIImage imageNamed:#"TVGuideTabImage.png"];
thirdTabImageView.image = [UIImage imageNamed:#"FirstRankTabImage.png"];
fourthTabImageView.image = [UIImage imageNamed:#"FavoriteTabImage.png"];
fifthTabImageView.image = [UIImage imageNamed:#"RegistrationTabImage_Active.png"];
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self makeTabBar];
MenuViewController *menuViewController = [[MenuViewController alloc] initWithNibName:#"MenuViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:menuViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
I use this code for every "IBAction" with different index :
For example : "FirstViewController" with "index: 0"
- (IBAction)GotoFirstViewController:(id)sender
{
AppDelegate *appdelegte = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[[[appdelegte navigationController] view]removeFromSuperview];
[[appdelegte window] addSubview:[[appdelegte tabBarController] view]];
[[appdelegte tabBarController] setSelectedIndex:0];
}
Now the problem is after going to a ViewController, and come back to "MenuViewController"
Useing this code :
-(IBAction)goBack:(id)sender
{
menuViewController = [[MenuViewController alloc] initWithNibName:#"MenuViewController" bundle:nil];
[self.navigationController pushViewController:menuViewController animated:YES];
}
I cannot go to another ViewController (any of five) pressing the same button.
If any one know, when the tabbar is setup from "seceondViewController (Here : firstViewController)" then after coming to the "firstViewController ( here : menuViewController)" from other ViewController, how to go again in the other ViewController which are connected with tabbar, please share with me.
Thanks a lot for reading this post and a lot thanks in advance.
- Tulon
- (void)addToolBarToView:(UIToolbar *)rootToolBar currentView:(UIViewController *)currentView{
CGRect rect = currentView.view.frame;
rootToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, rect.size.height-44, rect.size.width, 44)];
[rootToolBar setBarStyle:UIBarStyleDefault];
[rootToolBar sizeToFit];
UIBarButtonItem *searchBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"icon_ricerca.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(showSearch)];
UIBarButtonItem *cartBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"icon_shopping_cart.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(showCart)];
UIBarButtonItem *settingBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"icon_settings.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(showSettings)];
UIBarButtonItem *favoriteBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"icon_preferiti.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(showFavorites)];
UIBarButtonItem *savedBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"icon_save.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(showSaved)];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
NSArray *barItems = [NSArray arrayWithObjects:searchBtn, flexSpace, cartBtn, flexSpace, favoriteBtn, flexSpace, settingBtn, flexSpace, savedBtn ,nil];
[rootToolBar setItems:barItems animated:YES];
[currentView.view addSubview:rootToolBar];
}
Add this code at your AppDelegate.m
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
self.tabBarController.selectedViewController=viewController;
return YES;
}
Based on apple documentation UITabBar is a subclass of UIViewController and can be a child View..! But it must be the UIWindow rootController if not your app will crash!!! I had the same problem at the end I had to use UIToolBar to do the same thing.. though with a very hard work on customization.

How can I create unique PopoverView

How can I create special popOver?
I have manually created a new class, with needed design.
Then I want to load it like a PopOver
-(void) buttonAction {
UIViewController* popoverContent = [[UIViewController alloc] init];
myThirdPop * showHere;//Created class which I load as Popover
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"myThirdPop" owner:self options:nil];
showHere = [nib objectAtIndex:0];
popoverContent.view = showHere.myView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(300, 350);
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:myButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
But when I trying to tap the button, my app crashes with exc_bad_access
What`s wrong?
Use this code to create the popover
-(IBAction)Click_event
{ UIPopoverController *popoverview;
if(![popoverview isPopoverVisible])
{
Popview *pop = [[Popview alloc] initWithNibName:#"Popview" bundle:nil];
popoverview = [[UIPopoverController alloc] initWithContentViewController:pop];
[popoverview setPopoverContentSize:CGSizeMake(600.0f, 500.0f)];
[popoverview presentPopoverFromRect:CGRectMake(400, 400, 0, 0) inView:self.Click_but permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
else
{
[popoverview dismissPopoverAnimated:YES];
}
}
Lets try this. It may be helpful for you
Try this way u may fix the issue....
PopimagepickerViewController.h
UIPopoverController *popoverController;
UIPopoverController *popoverimagview; // imagepicker popoverview
PopimagepickerViewController.m
-(IBAction)popbtn_Click:(id)sender
{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,230,180)];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.view=popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(230, 180); // Set the popoverview Width and height
//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
CGRect popoverRect = [self.view convertRect:[popbtn frame]
fromView:[popbtn superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100) ;
popoverRect.origin.x = popoverRect.origin.x;
[popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp +
UIPopoverArrowDirectionLeft //pooverview down direction
animated:YES];
[popoverView release];
[popoverContent release];
}
Your code seems overly complex, and non standard. I use this code to create a popover.
(I've edited this to match your case, but it's not tested)
-(void) buttonAction:(id) sender
{
UIViewController *myThirdPop = [[NSBundle mainBundle] loadNibNamed:#"myThirdPop" owner:self options:nil];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:myThirdPop];
[popoverController presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[myThirdPop release];
}

Bottom half of UITabbar is not responding to clicks

I have created a UITabbar with 3 items and placed it on a UIScrollView
When I click the buttons of the tabbar they do not respond in the bottom half.
The upper area is working fine.
When clicking in the area just above the tabbar the tabs are also switched.
What can be wrong?
How can i correct this misalignment of the clickable button area?
In viewDidLoad:
[super viewDidLoad];
scroll.frame = CGRectMake(0, 20, 320, 460);
scroll.pagingEnabled = YES;
scroll.contentSize = CGSizeMake(320 * 2, 460);
scroll.showsHorizontalScrollIndicator = NO;
scroll.showsVerticalScrollIndicator = NO;
scroll.scrollsToTop = NO;
scroll.delegate = self;
scroll.pagingEnabled = YES;
viewNavController1 = [[viewNavController1 alloc] init];
ctrl = [[UITabBarController alloc] init];
ViewController1 *viewC1= [[ViewController1 alloc] initWithNibName:#"ViewController1" bundle:nil];
UINavigationController *control = [[UINavigationController alloc] initWithRootViewController:viewC1];
viewC1.title = #"Title1";
[viewC1 release];
ViewController2 *viewC2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
UINavigationController *control2 = [[UINavigationController alloc] initWithRootViewController:viewC2];
viewC2.title = #"Title2";
[viewC2 release];
UINavigationController *control3 = [[UINavigationController alloc] init];
ViewController3 *viewC3 = [[ViewController3 alloc] initWithNibName:#"ViewController3" bundle:nil];
[control3 pushViewController:viewC3 animated:NO];
viewC3.title = #"Title3";
[viewC3 release];
[ctrl setViewControllers:[NSArray arrayWithObjects:control,control2,control3,nil]];
CGRect frame = scroll.frame;
frame.origin.x = frame.size.width * 0;
frame.origin.y = 0;
viewNavController1.view.frame = frame;
viewC4 = [[ViewController4 alloc] initWithNibName:#"ViewController4" bundle:nil];
[viewNavController1 pushViewController:viewC4 animated:NO];
[scroll addSubview:viewNavController1.view];
frame = scroll.frame;
frame.origin.x = frame.size.width * 1;
frame.origin.y = 0;
ctrl.view.frame = frame;
[scroll addSubview:ctrl.view];
[scroll scrollRectToVisible:CGRectMake(320, 0, 320, 460) animated:NO];
UITabBarItem *itm = [ctrl.tabBar.items objectAtIndex:0];
itm.image = [UIImage imageNamed:#"img1.png"];
itm = [ctrl.tabBar.items objectAtIndex:1];
itm.image = [UIImage imageNamed:#"img2.png"];
itm = [ctrl.tabBar.items objectAtIndex:2];
itm.image = [UIImage imageNamed:#"img3.png"];
[control release];
[control2 release];
[control3 release];
The problem was that the UITabbarController did not have its view added as the root view of the windows. Which it apparently assumes.
so I had to trick it using:
[vc setWantsFullScreenLayout:YES];
vc is the main ViewController holding the scrollview containing the UITabbarController.
See Offset on UIWindow addSubview for more explanations.