iOS: TabBar controller above UIView - ios

I am having a problem with my tab bar placed above my view
I am using iOS 8 and Autolayout
I have my main view which has a button that opens another view that has the tab bar:
-(IBAction)btnOpen:(id)sender
{
Home* homevc = [[Home alloc] initWithNibName:#"Home_iPhone" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:homevc];
[nc.tabBarItem setTitle:#"Home"];
[nc.tabBarItem setImage:[UIImage imageNamed:#"home_icon.png"]];
Search *searchvc = [[Search alloc] initWithNibName:#"Search_iPhone" bundle:nil];
[searchvc.tabBarItem setTitle:#"Search"];
[searchvc.tabBarItem setImage:[UIImage imageNamed:#"search_icon.png"]];
UITabBarController *tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:[NSArray arrayWithObjects:nc,searchvc, nil]];
UIColor * color = [UIColor colorWithRed:191/255.0f green:50/255.0f blue:46/255.0f alpha:1.0f];
[[UITabBar appearance] setTintColor:color];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:color, NSForegroundColorAttributeName, nil]
forState:UIControlStateSelected];
[self presentViewController:tabController animated:YES completion:nil];
}
How can I place the Home view above the tab bar?

Related

Navigationbar right button is not placed correctly

I implemented a UITabBarController with 4 items.
I set the initial ViewController from AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
HomeTabBarViewController* homeVC = [[HomeTabBarViewController alloc] init];
[self.window setRootViewController:homeVC];
[self.window makeKeyAndVisible];
return YES;
}
Here is HomeTabBarViewController ViewDidLoad Code:
UIViewController *view1 = [[UIViewController alloc] init];
[view1.view setBackgroundColor:[UIColor redColor]];
UIViewController *view2 = [[UIViewController alloc] init];
UINavigationController * centerNav=[[UINavigationController alloc]initWithRootViewController:view1];
HomePagingViewController * view3=(HomePagingViewController*)[storyboard instantiateViewControllerWithIdentifier:#"HomePagingViewController"];
UINavigationController * centerNav3=[[UINavigationController alloc]initWithRootViewController:view3];
UIViewController *view4 = [[UIViewController alloc] init];
UINavigationController * centerNav4=[[UINavigationController alloc]initWithRootViewController:view4];
[view2.view setBackgroundColor:[UIColor greenColor]];
[view3.view setBackgroundColor:[UIColor purpleColor]];
[view4.view setBackgroundColor:[UIColor grayColor]];
NSMutableArray *tabViewControllers = [[NSMutableArray alloc] init];
[tabViewControllers addObject:centerNav];
[tabViewControllers addObject:view2];
[tabViewControllers addObject:centerNav3];
[tabViewControllers addObject:centerNav4];
[self setViewControllers:tabViewControllers];
view1.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Home"
image:[UIImage imageNamed:#"home_tab_item.png"] selectedImage:[UIImage imageNamed:#"home_tab_item_active.png"]] ;
view2.tabBarItem =
[[UITabBarItem alloc] initWithTitle:#"Bookmark"
image:[UIImage imageNamed:#"bookmark_tab_item.png"] selectedImage:[UIImage imageNamed:#"bookmark_tab_item_active.png"]];
view3.tabBarItem =
[[UITabBarItem alloc] initWithTitle:#"Paper"
image:[UIImage imageNamed:#"paper_tab_item.png"] selectedImage:[UIImage imageNamed:#"paper_tab_item_active.png"]];
view4.tabBarItem =
[[UITabBarItem alloc] initWithTitle:#"More"
image:[UIImage imageNamed:#"menu_tab_item.png"] selectedImage:[UIImage imageNamed:#"menu_tab_item_active.png"]];
In HomePagingViewController ViewDidLoad I setUp a Navigation as in code
-(void)navigationSetUp{
self.navigationController.navigationBar.translucent=NO;
UIBarButtonItem * settingBtn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"settings.png"] style:UIBarButtonItemStylePlain target:self action:#selector(menuHandler:)];
UIBarButtonItem * searchBtn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"settings.png"] style:UIBarButtonItemStylePlain target:self action:#selector(menuHandler:)];
self.navigationItem.leftBarButtonItem = settingBtn;
self.navigationItem.rightBarButtonItem = searchBtn;
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"ie_New_logo.png"]];
}
After this when I changed the tab for HomePagingViewController the navigation right button not placed correctly there is no margin from right.
Refer Image :
Please Help.
I resolved the issue , there is no issue with the code . Actually for Epaper we using third party SDK So that this problem occur.I Removed SDK & the code is working fine now.
you should think UIBarButtonSystemItemFixedSpace effect.
eg:
UIBarButtonItem * space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
--
Why use a system navigation bar ?Custom navigation bar is nice!like:https://github.com/chenliangloveyou/EasyNavigation

ios tabBarControl, navigationcontroller title and button editing

I've been using a standard TabBarController and top NavigationBar within my app. The tabBar loads in the appDelegate, initializes the navigationBar to use an image instead of center title, and this exists for all four tabBar views. Occasionally I'll push a new view onto the view controllers and that works well enough.
What I'd like to do is be able to change the NavigationBar for each of the 4 tabBar view controllers, when they are opened. I'm having trouble doing this. My initial navigationBar has an image, loaded in the appDelegate. My questions from here are:
Should each viewController generally create a new navigationBar from scratch, per its needs, in the respective viewWillAppear method?
What navigationController and navigationBar should be editted-- always the appDelegate's navigationController, the tabBarController.navigationController, or simply self.navigationController in each view? (generally, most editing most of these is not working for me, causes no changes to occur)
If I override the standard title (which is usually the tabBar's current view's title) with the imageView, and want another tabBar view to use the standard title, how should I remove the titleView image, and reset back to text? And viceVersa, dependent on view? This is what I'm really trying to accomplish unsuccessfully.
I guess I'm looking for standard practice in managing the navigationBar per view, and changing it per tabBarItem.
// in appDelegate
- (void)initNav {
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
self.tabBarController.navigationController.view.backgroundColor = [UIColor whiteColor];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.firstViewController,
self.secondViewController,
self.thirdViewController,
self.forthViewController,
nil];
[self.window addSubview:self.tabBarController.view];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.tabBarController];
self.navigationController.navigationBarHidden = NO;
// customize background color of nav bar to "blue"ish color
self.navigationController.navigationBar.backgroundColor = [UIColor colorWithHexString:#"00A3E1"];
self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:#"00A3E1"];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:#"00A3E1"];
[self createNavs];
}
// also in appDelegate
- (void)createNavs {
// white text when present
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
UITextAttributeTextColor,
[UIColor clearColor],
UITextAttributeTextShadowColor, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes: attributes
forState: UIControlStateNormal];
AppDelegate *delegateRef = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[self.navigationController.navigationBar setTranslucent:NO];
// setup left button (currently unused -- no left button)
/*
/*
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"glyphicons_049_star.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(starClick:) forControlEvents:UIControlEventTouchDown];
[button setFrame:CGRectMake(0, 0, 25, 25)];
self.navigationController.navigationBar.topItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
*/
// setup logo in center
self.tabBarController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"synced_top_logo.png"]];
// setup right button (currently unused -- no right button)
/*
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] init];
rightButton.title = #"edit";
[rightButton setTarget:self ];
[rightButton setAction:#selector(editClick:)];
self.navigationController.navigationBar.topItem.rightBarButtonItem = rightButton;
*/
[[self navigationController] setNavigationBarHidden:NO animated:YES];
[[delegateRef navigationController] setNavigationBarHidden:NO animated:YES];
}
EDIT:
This is a simplified version of the solution posted below that was helpful, and allowed the customization that was needed. Each view controller customizations its navigationbar independently from this. It was probably how it should have been done from the start.
tabBarController.viewControllers = [NSArray arrayWithObjects:[[UINavigationController alloc] initWithRootViewController:self.firstViewController],
[[UINavigationController alloc] initWithRootViewController:self.secondViewController],
[[UINavigationController alloc] initWithRootViewController:self.thirdViewController],
[[UINavigationController alloc] initWithRootViewController:self.forthViewController],
nil];
This maybe what you are needing:
- (void)initTabbar {
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
/*
You want each of your UIViewControllers to be wrapped in a UINavigationController. Then put each of those UINavigationControllers in a UITabBarController
*/
//You don't need to hang on to this becuase the proceeding UINavigationController will handle it
FirstViewController *firstViewController = [[FirstViewController alloc] ...];
//You'll need to declare this in your header
self.firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
//Second view allocation
SecondViewController *secondViewController = [[SecondViewController alloc] ...];
self.secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
//Third view allocation
ThirdViewController *thirdViewController = [[ThirdViewController alloc] ...];
self.thirdNavigationController = [[UINavigationController alloc] initWithRootViewController:thirdViewController];
//Now you add each of the UINavigationControllers (which is a subclass of UIViewController) to the UITabBarController.
self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.firstNavigationController,
self.secondNavigationController,
self.thirdNavigationController,
nil];
[self.window addSubview:self.tabBarController.view];
[self createNavs];
}
//This is more of a 'formatNavs' now
- (void)createNavs {
//Now you can customize each of the UINavigationController's UINavigationBars seperatly
self.firstNavigationController.navigationBar.backgroundColor = [UIColor colorWithHexString:#"00A3E1"];
self.firstNavigationController.navigationBar.tintColor = [UIColor colorWithHexString:#"00A3E1"];
self.firstNavigationController.navigationBar.barTintColor = [UIColor colorWithHexString:#"00A3E1"];
self.secondNavigationController.navigationBar.backgroundColor = [UIColor colorWithHexString:#"...."];
self.secondNavigationController.navigationBar.tintColor = [UIColor colorWithHexString:#"...."];
self.secondNavigationController.navigationBar.barTintColor = [UIColor colorWithHexString:#"...."];
self.thirdNavigationController.navigationBar.backgroundColor = [UIColor colorWithHexString:#"...."];
self.thirdNavigationController.navigationBar.tintColor = [UIColor colorWithHexString:#"...."];
self.thirdNavigationController.navigationBar.barTintColor = [UIColor colorWithHexString:#"...."];
}

UINavigationBar becomes black

First of all, when i call presentViewController:navigationController it appears with normal green color navigation bar. But after animation is finished navigation bar becomes a little darker.
if(!userPageViewController)
userPageViewController = [[UserPageViewController alloc]initWithUser:tempUser];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:userPageViewController];
[self presentViewController:navigationController animated:YES completion:nil];
When i press the home button, navigation bar becomes black like on this image.
https://dl.dropboxusercontent.com/u/14066789/2013-12-04%2012.27.45.png
Top bar in xib file is set to Translucent Navigation Bar
Why it becomes black?
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Личный кабинет";
[myTableView setBackgroundColor:[UIColor clearColor]];
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:#"Закрыть" style:UIBarButtonItemStyleBordered target:self action:#selector(backPressed:)];
self.navigationItem.leftBarButtonItem = btn;
self.navigationItem.backBarButtonItem = nil;
UIBarButtonItem *exitBtn = [[UIBarButtonItem alloc] initWithTitle:#"Выход" style:UIBarButtonItemStyleBordered target:self action:#selector(logOut:)];
self.navigationItem.rightBarButtonItem = exitBtn;
scroll.contentSize = CGSizeMake(320.0f, 400.0f);
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
}
-(void)viewWillAppear:(BOOL)animated
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
UIColor * barColor = [UIColor
colorWithRed:222.0/255.0
green:255.0/255.0
blue:229.0/255.0
alpha:1.0];
[self.navigationController.navigationBar setBarTintColor:barColor];
UIColor * barTintColor = [UIColor
colorWithRed:48.0/255.0
green:140.0/255.0
blue:76.0/255.0
alpha:1.0];
[self.navigationController.navigationBar setTintColor:barTintColor];
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
barTintColor,UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
}
else
{
UIColor * barColor = [UIColor
colorWithRed:73.0/255.0
green:208.0/255.0
blue:114.0/255.0
alpha:1.0];
[self.navigationController.navigationBar setTintColor:barColor];
}
}
I had the same problem.
Fixed by turning off "Transcluent" checkbox in properties of Navigation Bar of my root Navigation Controller in Storyboard.
You need to open left pane named "Document Outline" with small button in bottom left to find Navigation Bar.

Add navigation bar on a view controller

i am new on iOS and i wanna add a navigation bar on my view controller with 2 buttons back on left and subscribe on right. ive got no clue how to do it..till now i have just added a nav bar from interface builder, created a (strong)refrnce for it in .h file and did following coding.
navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, 1026, 50)];
[navBar setTintColor:[UIColor clearColor]];
[navBar setBackgroundColor:[UIColor redColor]];
[navBar setDelegate:self];
[self.view addSubview:navBar];
UIBarButtonItem *bi1 = [[UIBarButtonItem alloc] initWithTitle:#"subscribe" style:UIBarButtonItemStyleBordered target:self action:#selector(editBotton)];
bi1.style = UIBarButtonItemStyleBordered;
bi1.tintColor =[UIColor colorWithWhite:0.305f alpha:0.0f];
self.navigationItem.rightBarButtonItem = bi1;
but nothings happeing.. please help
You can add in AppDelegate,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone"
                                                             bundle: nil];
 
    SampleViewController *mainViewController = (SampleViewController*)[mainStoryboard
                                                       instantiateViewControllerWithIdentifier: #"SampleViewController"];
 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setRootViewController:navigationController];
    [self.window setBackgroundColor:[UIColor whiteColor]];
    [self.window makeKeyAndVisible];
 
    return YES;
}
I think you have to learn the basic concepts about UINavigationController. You can learn from the below tutorials:
http://simplecode.me/2011/09/04/an-introduction-to-uinavigationcontroller/
http://www.ralfebert.de/archive/ios/tutorial_iosdev/navigationcontroller/
http://bharanijayasuri.wordpress.com/2012/12/19/simple-uinavigationcontroller-tutorial-2/

IOS7 navigatinBar tintColor change in popover

I developed iPad application. I'm opening some screens in popover with navigation controller. But I did not change navigationcontroller tint color in IOS 7. How can I change this color. thanx
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:airportsSearch] autorelease];
navigationController.navigationBar.barTintColor = [UIColor blackColor];
navigationController.navigationBar.translucent = NO;
self.popOver=[[UIPopoverController alloc] initWithContentViewController:navigationController];
self.popOver.delegate = self;
[self.popOver setPopoverContentSize:CGSizeMake(285, 370)];
[self.popOver presentPopoverFromRect:tempButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
The magical word here is barStyle, you need to do the following if you need it black:
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.translucent = NO;
And if you want to change its color:
navigationController.navigationBar.barTintColor = [UIColor redColor];
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.translucent = NO;
Setting the NavigationBarStyle to UIBarStyleBlack also worked for me, but only via the Storyboard.
I tried
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
as well as
[[UINavigationBar appearanceWhenContainedIn:[UIPopoverController class], nil] setBarStyle:UIBarStyleBlack];
in the didFinishLaunchingWithOptions AppDelegate method. But nothing changed. Only changing the BarStyle of the NavigationControllers NavigationBar inside the Storyboard worked.

Resources