UINavigationBar becomes black - ios

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.

Related

iOS - How to custom vertical position of navigation back bar item

I have a design of navigation bar like this. I've ready increased the height of Navigation Bar, but how can I set the position of Back button image and align left the title?
#import "UINavigationBar+Custom.h"
#implementation UINavigationBar (Custom)
- (CGSize)sizeThatFits:(CGSize)size {
CGRect rec = self.frame;
CGRect screenRect = [[UIScreen mainScreen] bounds];
rec.size.width = screenRect.size.width;
rec.size.height = 77;
return rec.size;
}
#end
NavBar picture design
Reality
Update: My code to add back bar button
- (void)viewDidLoad {
[super viewDidLoad];
[self configNavBar];
}
- (void)configNavBar {
// -- Config NavigationBar Background --
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;
// -- Navigator title font --
NSDictionary *titleAttributes = #{
NSFontAttributeName :FONT_NAVIGATION_TITLE_BAR,
NSForegroundColorAttributeName : [Utils colorWithHexString:#"#0f385a"] };
[self.navigationController.navigationBar setTitleTextAttributes:titleAttributes];
// -- Back button color --
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
UIImage *myImage = [UIImage imageNamed:#"ic_arrow_back"]; //set your backbutton imagename
UIImage *backButtonImage = [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// now use the new backButtomImage
[[UINavigationBar appearance] setBackIndicatorImage:backButtonImage];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backButtonImage];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-0.f, -0)
forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundVerticalPositionAdjustment:40 forBarMetrics:UIBarMetricsDefault];
// -- Empty back title --
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButtonItem];
}
Try this codeUIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"image"] style:UIBarButtonItemStylePlain target:self action:#selector(action)];
[self.navigationItem setLeftBarButtonItem:barButtonItem];. And correctly format the image

CNContactPickerViewcontroller navigationBar color

how do i change the black bar to another color?
N.B this is a CNContactPickerViewcontroller...the first screen(list of contacts) looks fine but when i click on a contact to choose a specific contact property then the navigation bar turns black.
Thanks
One way is to set the Appearance of UINavigationBar to the color you want:
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
And once you return to the previous ViewController (Maybe with -(void)viewWillAppear:(BOOL)animated) you set it again to the previous color you were using.
I presented the Contact this way:
CNContactStore *store = [[CNContactStore alloc] init];
// Create contact
CNMutableContact *contact = [[CNMutableContact alloc] init];
contact.givenName = #"Someone Name";
CNLabeledValue *contactPhoneNumber = [CNLabeledValue labeledValueWithLabel:CNLabelHome value:[CNPhoneNumber phoneNumberWithStringValue:#"Some number"]];
contact.phoneNumbers = #[contactPhoneNumber];
CNContactViewController *contactController = [CNContactViewController viewControllerForUnknownContact:contact];
contactController.navigationItem.title = #"Add to contacts";
contactController.contactStore = store;
contactController.delegate = self;
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName : [UIColor blackColor]};
[self.navigationController pushViewController:contactController animated:YES];
Once the contactController is Dismissed the viewWillAppear is called and you can add there the color restore depending on your needs:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName : [UIColor whiteColor]};
}
I've solved it by changing the backgroundColor of the navbar subviews after a delay, not pretty, but it's good enough for me:
CNContactViewController *vc = [CNContactViewController viewControllerForContact:contact];
vc.delegate = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
for (UIView *view in [vc.navigationController.navigationBar subviews]) {
view.tintColor = [UIColor darkTextColor];
view.backgroundColor = [UIColor redColor];
}
});
[self.navigationController pushViewController:vc animated:YES];

NAvigation bar not appear

I want to make my NavigationbarClear color. So I tried like this in my ViewDidLoad
self.navigationController.navigationBar.hidden=NO;
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage=[UIImage new];
self.navigationController.navigationBar.translucent=YES;
self.navigationController.navigationBar.topItem.titleView.tintColor=[UIColor blackColor];
self.navigationController.navigationBar.topItem.title=[lan GetConvertedLanguageString:#"My Profile"];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"backarrow"] style:UIBarButtonItemStylePlain target:self action:#selector(revealToggle :)];
[self.navigationController navigationBar].tintColor = [UIColor whiteColor];
But nothing visible in my view controller. Whats wrong with this code? Please help me.
Thanks
Pick up navigation controller scene and then pickup navigationbar (see in pic) after that set the clear color from showutilites>attribute insepecter also you can change title color from here
Screenshot
Code
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage=[UIImage new];
self.navigationItem.title = #"1234";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Left" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
[self.navigationController navigationBar].tintColor = [UIColor whiteColor];
So,I guess,your background of View is White,so you cannot see white text.
Note
navigationBar.titleTextAttributes
Display attributes for the bar’s title text.
navigationBar.tintColor
The tint color to apply to the navigation items and bar button items.

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 title overlaps momentarily on VC load with Custom NavBar Height

I have a custom method in my AppDelegate:
-(void)setupNavBar{
UINavigationController *nav = (UINavigationController *)self.window.rootViewController;
[nav.navigationBar setBounds:CGRectMake(0,0,320,70)];
nav.navigationBar.translucent = YES;
[nav.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav.navigationBar.shadowImage = [UIImage new];
nav.navigationBar.translucent = YES;
nav.view.backgroundColor = [UIColor clearColor];
UIView *navBorder = [[UIView alloc] initWithFrame:CGRectMake(0, nav.navigationBar.frame.size.height-1, nav.navigationBar.frame.size.width, 1)];
// Change the frame size to suit yours //
[navBorder setBackgroundColor:[UIColor colorWithWhite:200.0f/255.f alpha:0.8f]];
[navBorder setOpaque:YES];
[nav.navigationBar addSubview:navBorder];
CGFloat verticalOffset = 25;
[nav.navigationBar setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTintColor:[UIColor clearColor]];
[[UINavigationBar appearance] setTitleTextAttributes:#{
UITextAttributeTextColor: [UIColor whiteColor],
UITextAttributeFont: [UIFont fontWithName:#"Dosis-ExtraBold" size:33.0],
}];
}
I am presenting using a Nav Controller on storyboard and on the initial view controller everything looks great. However, when I push another VC (via segue) the title only half shows before the Navigationbar area seems to resize and redraw. Is there anyway to force a redraw in the ViewWillAppear so that the title text shows up whole straight away?
Have attached some images of the transition.
Thanks.
http://puu.sh/7AkJL
Try to use this:
- (void)viewDidLoad
{
//your code
self.navigationItem.titleView = [self initTitle: #"IN HAND"];
}
- (UIView *)initTitle:(NSString *) titleString
{
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 180, 44)]; //your size!
UILabel *navBarLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
navBarLabel.text = titleString;
[navBarLabel setTextAlignment:NSTextAlignmentCenter];
navBarLabel.font = [UIFont fontWithName:#"Menlo-Regular" size:16.0f];
navBarLabel.textColor = [UIColor whiteColor];
[titleView addSubview:navBarLabel];
return titleView;
}

Resources