Reputation: 217
I'm having an issue with text color of navigation bar item on iOS7.
All things are fine until I present a viewcontroller, from this time, all navigation bar items text color are Grey. Do you have any experience with this issue?
The codes used to present VC:
[passcodePopover presentPopoverFromRect:CGRectMake([UIScreen mainScreen].bounds.size.width/2 ,currentWindow.frame.size.height/2,1,1)
inView:currentWindow
permittedArrowDirections:0 animated:NO];[passcodePopover presentPopoverFromRect:CGRectMake([UIScreen mainScreen].bounds.size.width/2 ,currentWindow.frame.size.height/2,1,1)
inView:currentWindow
permittedArrowDirections:0 animated:NO];
Upvotes: 0
Views: 3718
Reputation: 313
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],
NSForegroundColorAttributeName,[UIColor whiteColor],
NSForegroundColorAttributeName,[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
NSForegroundColorAttributeName,[UIFont fontWithName:@"Arial-Bold" size:0.0],
NSFontAttributeName,nil]];
Upvotes: 1
Reputation: 17595
You can use this. It may help you.. Here I've set font and text color
for two states.
[barItemForIndex setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont systemFontOfSize:Tabbar_Item_Font_Size], NSFontAttributeName,
[UIColor darkGrayColor], NSForegroundColorAttributeName,
nil] forState:UIControlStateNormal];
[barItemForIndex setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont systemFontOfSize:Tabbar_Item_Font_Size], NSFontAttributeName,
[UIColor whiteColor], NSForegroundColorAttributeName,
nil] forState:UIControlStateSelected];
Note : setTitleTextAttributes:
method only available ios5.0+.
Upvotes: 0
Reputation: 12908
create a category instead:
@implementation UINavigationBar (custom)
- (void)setCustomNavigationBar: (NSString *)_strTitle
{
[self setBackgroundImage:[UIImage imageNamed:@"navigationbar"] forBarMetrics:UIBarMetricsDefault];
UILabel *_lblTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
_lblTitle.text = _strTitle;
_lblTitle.textAlignment = NSTextAlignmentCenter;
[_lblTitle setBackgroundColor:[UIColor clearColor]];
[_lblTitle setFont:[UIFont fontWithName:kAppFontBold size:kAppFontBoldSize]];
[_lblTitle setTextColor:[UIColor navigationBarColor]];
[[self topItem] setTitleView:_lblTitle];
}
Where kAppFontBold
and kAppFontBoldSize
are macros.
Upvotes: 0
Reputation: 313
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero] ;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0]; // font size
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor yellowColor]; // change this color
self.navigationItem.titleView = label;
label.text = NSLocalizedString(@"Product Info.", @""); // lable name
[label sizeToFit];
Upvotes: 1
Reputation: 82769
//call the below code in ViewDidLoad /It works fine in iOS7
UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 320, 100)];
navLabel.backgroundColor = [UIColor clearColor];
navLabel.text = @"Event Details";
navLabel.textColor = [UIColor whiteColor];
navLabel.shadowOffset = CGSizeMake(0, -2);
[navLabel setFont:[UIFont boldSystemFontOfSize:16]];
navLabel.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = navLabel;
Upvotes: 1
Reputation: 3605
use below code in viewdid Load function
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
[[UINavigationBar appearance]setTintColor:NavigationColor];
} else
{
[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]]; // it set color of bar button item text
}
Upvotes: 0
Reputation: 3970
In the passcodePopover's viewdidLoad method you will want to use this code.
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil];
[self.navigationController.navigationBar setTitleTextAttributes:textTitleOptions];
If you don't have a navigationController in your popover you will have to change the code slightly, also you may not want to use [UIColor whiteColor]. Instead substitute your own choice of color.
Upvotes: 0