JWK
JWK

Reputation: 3780

Using NSShadow on Navigation Bar Button Items in iOS 7

I have a navigation bar that looks like so:

enter image description here

It was created with the following code:

//  AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    NSShadow *textShadow = [[NSShadow alloc] init];
    textShadow.shadowBlurRadius = 5.0;
    textShadow.shadowColor = [UIColor colorWithWhite: 1.0 alpha: 0.75];
    textShadow.shadowOffset = CGSizeMake(0.0, 1.0);
    [[UIBarButtonItem appearance] setTitleTextAttributes: @{ NSShadowAttributeName: textShadow } forState: UIControlStateNormal];

    return YES;
}

Questions

  1. Where is the shadowBlurRadius (at least for the "Edit" button)? Notice that I set textShadow.shadowBlurRadius = 5.0;. Cranking up that value doesn't seem to do anything either.
  2. Is it possible to add a shadow to the "+" bar button item or other bar button items that are not text (e.g. UIBarButtonSystemItemCamera)? I'd like to avoid generating my own rasterized images.

This question pertains to iOS 7 only.

Upvotes: 1

Views: 1316

Answers (1)

Balram Tiwari
Balram Tiwari

Reputation: 5667

Actually your shadow is getting rendered on UIBarButonItem & you can see the white shadow in the "Edit" bar button item text. If you want to use better shadow appearance then please try to play with values in CGSizeMake here within range of -1, 1, 0

textShadow.shadowOffset = CGSizeMake(0.0, -1.0);

A bit tricky, but to add shadow to the right bar button item, please make a UIBarButton with title on it as + & assign it to the rightBarButton of navigation Item & you will get the shadow affect as you see in the left bar button item.

Hopw that helps.

Upvotes: 1

Related Questions