Question

Solution

Now based on the idea given by @visualication, this following code (put it in application:didFinishLaunchingWithOptions:) will solve the problem:

[[[self navigationController] navigationBar] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], UITextAttributeTextShadowColor:[UIColor whiteColor], UITextAttributeTextShadowOffset:[NSValue valueWithUIOffset:UIOffsetMake(0, 0)]}];

Screenshot now on iOS 6:

enter image description here

Original Post

Have a look of this screenshot on iOS 6:

enter image description here

The title has some black shadow along with it, I didn't code the shadow, I just give the background image, 320-point wide, 44-point high, with a kind of red color.

    /// Create background image for navigation bar in iOS 6 or prior programmatically
    CGRect rect = CGRectMake(0.0f, 0.0f, screenBoundsRect.size.width, 44.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [[UIColor colorWithRed:201/255.f green:32/255.f blue:38/255.f alpha:1.00] CGColor]); // a red color
    CGContextFillRect(context, rect);
    UIImage *navigationBarBackgroundImageForiOS6 = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [[[self navigationController] navigationBar] setBackgroundImage:navigationBarBackgroundImageForiOS6 forBarMetrics:UIBarMetricsDefault]; // UIBarMetricsDefault is portrait in iPhone

And set the title to navigation bar using this code:

    /// Set the title
    [[[self navigationController] topViewController] setTitle:@"dynamiclc2"];

The above title setting code gives shadow in iOS 6 but doesn't give shadow in iOS 7:

enter image description here

I want the navigation bar's title in iOS 6 display the same (or nearly the same) with the iOS 7 version.

Was it helpful?

Solution

you can set the shadow lIkE this:

[[UINavigationBar appearance] setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0],
  UITextAttributeTextShadowColor,
  [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
  UITextAttributeTextShadowOffset,
  nil]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top