How to set Font Of tabbar title in objective-C - ios

I want to set font of tabBar title as ubuntu but I can't set that.
I write below code for that:
self.tabBarController.navigationController.navigationBar.titleTextAttributes =
#{NSForegroundColorAttributeName: [UIColor whiteColor],
NSFontAttributeName:[UIFont fontWithName:#"Ubuntu" size:9.0f]};

Objective C Code-
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:#"your_font_name" size:20.0f], NSFontAttributeName, nil] forState:UIControlStateNormal];
Swift Code-
UITabBarItem.appearance().setTitleTextAttributes(
[NSFontAttributeName: UIFont(name:"your_font_name", size:11)!,
NSForegroundColorAttributeName: UIColor(rgb: 0x929292)],
forState: .Normal)
For more refrence-
iOS5 TabBar Fonts and Color

i found one solution..
first i create custom label and after that i change font of that....
UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0,0,230.0,80.0)];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 230, 80)];
lbl.textColor = [UIColor whiteColor];
lbl.font = [UIFont fontWithName:#"Ubuntu" size:18.0f];
lbl.textAlignment = NSTextAlignmentCenter;
lbl.text = [NSString stringWithFormat:#"%lu Store Found",(unsigned long)arrOfferList.count];
[iv addSubview:lbl];
self.tabBarController.navigationItem.titleView = iv;

Related

Navigation Title Chopped with external Font 'FuturaStd-Book'

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:

Need change title navbar color

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;

Centering Label Vertically in UINavigationBar TitleView

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()]

Change UIToolbar Font Size - iOS

Is there a way to change the size of the font in a UIToolbar? My text does not fit so I need to make it smaller.
Thanks!
Here is one example. I am not sure what you want, but you can resize the font size of uibarbuttonitem in uitoolbar.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,10,15)];
label.font = [UIFont systemFontOfSize:15.0];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
//label.adjustsFontSizeToFitWidth = YES;
label.textAlignment = UITextAlignmentCenter;
label.text = #"Bar";
UIBarButtonItem *item2 = [[UIBarButtonItem alloc]
initWithCustomView:label];

Change font of UINavigationController title

Can I change the font of my UINavigationController? --> title
As of iOS 5 you can change the font via the appearance proxy.
https://developer.apple.com/documentation/uikit/uiappearance
The following will set the title font for all UINavigationControllers.
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
[titleBarAttributes setValue:[UIFont fontWithName:#"Didot" size:16] forKey:NSFontAttributeName];
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];
To set the font for the back button, do this:
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary: [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateNormal]];
[attributes setValue:[UIFont fontWithName:#"Didot" size:12] forKey:NSFontAttributeName];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
To set the font for the large titles available in iOS 11+, do this:
if (#available(iOS 11.0, *)) {
NSMutableDictionary *largeTitleTextAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] largeTitleTextAttributes]];
[largeTitleTextAttributes setValue:[UIFont fontWithName:#"Didot" size:32] forKey:NSFontAttributeName];
[[UINavigationBar appearance] setLargeTitleTextAttributes:largeTitleTextAttributes];
}
for iOS8+ you can use:
[self.navigationController.navigationBar setTitleTextAttributes:#{ NSFontAttributeName: [UIFont fontWithName:#"MyFont" size:18.0f],
NSForegroundColorAttributeName: [UIColor whiteColor]
}];
Swift:
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "MyFont", size: 18.0)!]
The title view can be any view. So just create a UILabel or something else where you change the font and assign that new view to the title property of the navigation item.
An example:
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
CGRect frame = CGRectMake(0, 0, 400, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [FontHelper fontFor:FontTargetForNavigationHeadings];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = self.navigationItem.title;
// emboss in the same way as the native title
[label setShadowColor:[UIColor darkGrayColor]];
[label setShadowOffset:CGSizeMake(0, -0.5)];
self.navigationItem.titleView = label;
}
The answer from #morgancodes will set the font for all UINavigationController titles. I've updated it for Swift 4:
let attributes = [NSAttributedStringKey.font: UIFont(name: "Menlo", size: 14) as Any]
UINavigationBar.appearance().titleTextAttributes = attributes
UIBarButtonItem.appearance().setTitleTextAttributes(attributes, for: .normal)

Resources