Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 10    Views: 70

PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
03/19/14 09:49 PM (10 years ago)

Where to place nav bar title font information?

Hi all, I've followed Smug's tutorial on installing a custom font and I <think> I've got that right. However I'm having difficulty working out where to apply that font. I want it to apply to the nav bar Title text on every screen. The interwebs tell me that this is what's needed to apply the font (with some shadow styling etc): NSShadow* shadow = [NSShadow new]; shadow.shadowOffset = CGSizeMake(0.0f, 1.0f); shadow.shadowColor = [UIColor brownColor]; [[UINavigationBar appearance] setTitleTextAttributes: @{ NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:@"Oxygen" size:21.0f], NSShadowAttributeName: shadow }]; but I can't for the life of me work out where to put it (and I've tried many places in many files!!) I would have thought that it would go in the appDelegate (where the colour of the Title text is set) but that doesn't seem to be having an effect. Same deal in the BT_viewController. Any ideas? What am I missing? Cheers Paddy.
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/19/14 10:41 PM (10 years ago)
Shot in the dark ... have you tried it in the viewDidLoad of a plugin's screen? ( it won't change it everywhere, only for that screen )
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
03/19/14 10:51 PM (10 years ago)
Good idea Niraj... I've now tried that in a few plugins but it doesn't seem to be changing anything.
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
03/19/14 11:02 PM (10 years ago)
this is what works for me - put this in the viewDidLoad of the plugin UILabel *navLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300,40)]; navLabel.backgroundColor = [UIColor clearColor]; navLabel.textColor = [BT_color getColorFromHexString:@"#8CE1CD"]; navLabel.text = @"Your Text Here"; navLabel.textAlignment = NSTextAlignmentCenter; [navLabel setFont:[UIFont fontWithName:@"Arial Rounded MT Bold" size:15]]; self.navigationItem.titleView = navLabel; Obviously, you'll probably want to edit a few of those values...such as the textColor and the font/font size
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
03/19/14 11:37 PM (10 years ago)
Thanks Absentia, I'll give it a try. Cheers Paddy.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/20/14 12:30 AM (10 years ago)
If you want 'global' coverage in one fell swoop, line 373 of the BT_viewController needs to be changed to something like this: self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"yourFontName" size:20], UITextAttributeFont, nil]; if you want a particular color or other text attribute, that's the place to include it. Cheers! -- Smug
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
03/20/14 10:57 AM (10 years ago)
So the viewController is like what css is in web design, in a sense?
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
03/20/14 10:41 PM (10 years ago)
Got it! Smug's code worked (of course!!) to make it a global change, but only when I put it at line 86 or so in BT_viewController, after self configureNavBar]; (of course!!) Inserting it at line 373 didn't do anything there, Smug. Interestingly, I didn't specify text colour in that, but the nav Title text has now reverted to the default colour (black), whereas I had set the colour of all nav bar text to white in the appDelegate below line 92 " Nav Bar Title Text Color" [self setNavBarTitleTextColor:@"#FFFFFF"]; A bit more digging required, but thanks everyone for getting me to this point! Cheers Paddy.
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
03/20/14 11:47 PM (10 years ago)
OK, it looks like I need some better brains on this... As above, this works well in BT_viewController to change the font for the nav bar Title text (thanks Smug): [self configureNavBar]; self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Oxygen" size:21], UITextAttributeFont, nil]; But whilst it changes the font beautfully, it also changes the color back to the default black. I want it white, but try to do that using this in on the next line: [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}]; it does revert to white, but I lose the font change! The colour of the left and right buttons in the nav bar is still being declared in the appDelegate file, and that's having no effect on the colour of the Title text (unless that last bit of code is commented out, at which point the appDelegate specs seem to kick back in). What am I not seeing or understanding?
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
03/21/14 12:04 AM (10 years ago)
Sorry for all this thinking out loud - problem solved, I got it: self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Oxygen" size:21], UITextAttributeFont, [UIColor whiteColor], UITextAttributeTextColor, nil]; Phew. Cheers Paddy.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/21/14 06:18 AM (10 years ago)
Sorry about that; I was guessing, lol! I figured I had the instruction correctly… but the last time I used it was in a BTv2 project, where it's in a completely different file… Thanks for figuring it out, now I won't have to, lol! :) Cheers! -- Smug
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.