Need change navigationbar title color.
Something like that:
self.navigationItem.title.color = [UIColor yellowColor];
-(void)viewDidLoad
{
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
// In dictionary you can set your own color
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,shadow, NSShadowAttributeName,[UIFont fontWithName:#"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
}
for more...
go to http://www.appcoda.com/customize-navigation-status-bar-ios-7/
hope this will help you
you can give any stylish you want to tittle of navigation bar by just doing
UILabel *lblNavTitle = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
lblNavTitle.backgroundColor = [UIColor clearColor];
lblNavTitle.textAlignment = NSTextAlignmentCenter;
lblNavTitle.textColor = [UIColor whiteColor];//this what you want
lblNavTitle.text = NSLocalizedString(#"Volunteers", #"");
[lblNavTitle sizeToFit];
self.navigationItem.titleView = lblNavTitle;
Related
Title chopped in Navigation with external Font 'FuturaStd-Book'.
Tried to decreased Font size with following code but still title chopped.
[[UINavigationBar appearance] setTitleTextAttributes:#{NSFontAttributeName:[UIFont fontWithName:#"FuturaStd-Book" size:16]}];
Kindly help me on this...
Following code to Align the navigationItem title. (Only Works from iOS 11 - but the Navigation back and Title y position differs )
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
style.alignment = NSTextAlignmentCenter;
style.firstLineHeadIndent = 1.0f;
style.lineSpacing = 2; //Change spacing between lines
style.paragraphSpacing = 2; //Change space between paragraphs
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor blackColor],
NSBackgroundColorAttributeName:[UIColor clearColor],
NSFontAttributeName:[UIFont fontWithName:#"FuturaStd-Book" size:18],
NSParagraphStyleAttributeName: style }];
You've to use the titleView of the navigationItem. Try this in your VC:
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 44.0)];
headerLabel.textAlignment = NSTextAlignmentCenter;
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.text = #"Register";
headerLabel.font = [UIFont fontWithName:#"FuturaStd-Book" size:16];
headerLabel.textColor = [UIColor blackColor];
self.navigationItem.titleView = headerLabel;
Output:
I want to change the title color of keyboard toobar i.e(submit button), and the other is how can I add the image for keyboard toolbar. TIA
UIToolbar *keyboardToolbar = [[UIToolbar alloc] init];
[keyboardToolbar sizeToFit];
keyboardToolbar.translucent=NO; //if you want it.
keyboardToolbar.barTintColor = [UIColor lightGrayColor];
_txtCommentView.inputAccessoryView = keyboardToolbar;
keyboardToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:#"Submit" style:UIBarButtonItemStyleBordered target:self action:#selector(submitClicked:)],
nil];
Try below code and do changes as per your requirement:
UIToolbar *keyboardToolbar = [[UIToolbar alloc] init];
[keyboardToolbar sizeToFit];
keyboardToolbar.translucent=NO; //if you want it.
keyboardToolbar.barTintColor = [UIColor lightGrayColor];
_txtCommentView.inputAccessoryView = keyboardToolbar;
UIBarButtonItem *submit = [[UIBarButtonItem alloc] initWithTitle:#"Submit"
style:UIBarButtonItemStyleBordered
target:self action:#selector(submitClicked:)];
//Change submit button attributes here as you want
[submit setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Helvetica-Bold" size:18.0], NSFontAttributeName,
[UIColor whiteColor], NSForegroundColorAttributeName,
nil] forState:UIControlStateNormal];
keyboardToolbar.items = [NSArray arrayWithObjects:submit, nil];
If you want to change the change in whole application Toolbar then Use
[UIToolbar appearance].tintColor = [UIColor redColor];
[UIToolbar appearance].barTintColor = [UIColor greenColor];
Also you can Use below code to change :
NSDictionary *attributes = #{
NSForegroundColorAttributeName: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0],
NSFontAttributeName: [UIFont fontWithName:#"Arial" size:16.0]
};
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
I have a problem with my top bar, i initialize a color in my MainViewController with a function that is used in the viewDidLoad :
-(void)_initCustomTopBar
{
NSLog(#"init");
UIColor *barColour = [UIColor colorWithRed:22.0f/255.0f green:61.0f/255.0f blue:121.0f/255.0f alpha:1.0f];
UIView *colourView = [[UIView alloc] initWithFrame:CGRectMake(0.f, -20.f, 320.f, 64.f)];
colourView.opaque = NO;
colourView.alpha = .7f;
//colourView.backgroundColor = barColour;
self.navigationController.navigationBar.barTintColor = barColour;
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar.layer insertSublayer:colourView.layer atIndex:1];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont
fontWithName:#"Helvetica Neue" size:20], NSFontAttributeName,
[UIColor whiteColor], NSForegroundColorAttributeName, nil];
self.navigationController.navigationBar.titleTextAttributes = attributes;
}
But when i change of view, the top bar became gray and when i click on return the MainViewController top bar became gray too.
Have an idea for why it became gray ? And how correct that ?
Call this _initCustomTopBar in your viewWillAppear method
-(void)viewWillAppear:(BOOL)animated
{
[self _initCustomTopBar];
}
This crashes the app:
[[UINavigationBar appearance] setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
Is there a way to do this using appearance?
This worked:
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, nil];
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];
Here's an example of how to do this in Swift:
UINavigationBar.appearance().titleTextAttributes =
[NSFontAttributeName:UIFont(name:"Exo2-Bold", size: 18) as! AnyObject,
NSForegroundColorAttributeName:UIColor.whiteColor()]
That crashes the app before UINavigationBar doesn't have a title or state... Those are UIButton methods
You need
[[UINavigationBar appearance] setTintColor:[UIColor darkGrayColor]];
The #RyJ answer is great and worked for me. Thought I'd chip in that there's a good tutorial on this in Ray Wenderlich's site, titled (excuse the pun):
User Interface Customization in iOS 6
See the section Customizing UINavigationBar
Here's the code snippet for the navigation bar title, to change globally:
// Customize the title text for *all* UINavigationBars
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Arial-Bold" size:0.0],
UITextAttributeFont,
nil]];
One other minor point is that it seems there's a default shadow on the title bar, so to get rid of it, you can't just remove the attribute. Instead you have to set a shadow offset:
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0, 0)]
for iOS 15
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = <PREFERRED BACKGROUND COLOR>
appearance.titleTextAttributes = [.foregroundColor : <PREFERRED TITLE COLOR>]
navigationBar.tintColor = <PREFERED TINT COLOR> //for bar buttons
navigationBar.standardAppearance = appearance;
navigationBar.scrollEdgeAppearance = navigationBar.standardAppearance
I used following code to change the title bar's color.
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor blackColor];
shadow.shadowOffset = CGSizeMake(1, 0);
NSDictionary *titleTextAttributes = #{NSForegroundColorAttributeName:[UIColor whiteColor],
NSShadowAttributeName:shadow};
[[UINavigationBar appearance] setTitleTextAttributes:titleTextAttributes];
Using modern syntax and code that actually runs, this is how to globally style your UINavigationBar title text:
NSShadow *navigationBarTitleShadow = [[NSShadow alloc] init];
navigationBarTitleShadow.shadowColor = [UIColor colorWithWhite:0.5
alpha:0.5];
navigationBarTitleShadow.shadowOffset = CGSizeMake(2.0, 2.0);
[[UINavigationBar appearance] setTitleTextAttributes:#{ NSForegroundColorAttributeName : [UIColor blackColor],
NSFontAttributeName : [UIFont fontWithName:#"Arial-BoldMT"
size:30.0],
NSShadowAttributeName : navigationBarTitleShadow }];
Note: NSShadow's shadowBlurRadius property is not respected.
Note: Shadows are so iOS 6. Don't ever use them.
I'm not having much luck centering vertically the label I'm adding to the TitleView on the UINavigationBar. You can see what it looks like below.
This is how I'm adding the label:
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = NSLocalizedString(#"activeSessionsTitle",#"");
titleLabel.font = [Util SETTING_NEO_HEADER_FONT];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.shadowColor = [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.25f];
titleLabel.shadowOffset = CGSizeMake(0.0f, -1.0f);
[titleLabel sizeToFit];
super.navigationItem.titleView = titleLabel;
I think the reason why it's doing this is there is something weird with the actual font I'm using -- as I've had to do a lot of repositioning inside of buttons and such. I've been able to solve the issue everywhere but the navigation bar.
Opening up an old Question, but I found this to be very useful.
iOS 5 allows your to use [UINavigationBar appearance] which is great for changing the Title bar's title view without the need for a custom UIView:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"HelveticaNeue" size:25.0f],
UITextAttributeFont,
nil]];
Sometimes, depending on the UIFont that you use, the title view may be vertically off.
To fix this, you can use:
[self.navigationBar setTitleVerticalPositionAdjustment:(float) forBarMetrics:UIBarMetricsDefault];
(float) being a positive value to push the titleView down, and a negative value to push the titleView up.
I hope this helps.
I ended up using a combination of the answer RPM left and one of the comments on my question. This is what ultimately fixed it for me:
UIView *customTitleView = [[UIView alloc] init];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 3.0f, 200.0f, 30.0f)];
titleLabel.text = titleString;
titleLabel.font = [Util SETTING_NEO_HEADER_FONT];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.shadowColor = [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.25f];
titleLabel.shadowOffset = CGSizeMake(0.0f, -1.0f);
[titleLabel sizeToFit];
customTitleView.frame = CGRectMake(self.navigationItem.titleView.frame.size.width/2 - titleLabel.frame.size.width/2, self.navigationItem.titleView.frame.size.height/2 - titleLabel.frame.size.height/2, titleLabel.frame.size.width, titleLabel.frame.size.height);
[customTitleView addSubview:titleLabel];
[titleLabel release];
[self.navigationItem setTitleView:customTitleView];
[customTitleView release];
If you're using this chunk of code, you may have to play with the "y" value on the title label's initWithFrame: call. I have it set to 3.0f, but you may have to adjust it a bit for your own usage.
The reason the other solutions didn't seem to work for me is they would go off-center horizontally depending if I had one barbutton (left or right). If there were no bar buttons it was fine, and if there were two it was fine. But one would cause it to go off-center.
I dont think this has anything to do with your font. I have also used titleView and I think the way it lays out the view in a weird way and doesnt take into consideration what your view size is.
You could also set the frame of your label view as such
titleLabel.frame = CGRectMake(self.navigationItem.titleView.frame.size.width/2 - titleLabel.frame.size.width/2, self.navigationItem.titleView.frame.size.height/2 - titleLabel.frame.size.height/2, titleLabel.frame.size.width, titleLabel.frame.size.height);
self.navigationItem.titleView = titleLabel;
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName:UIFont(name:"Exo2-Bold", size: 18) as! AnyObject,NSForegroundColorAttributeName:UIColor.whiteColor()]