Adding shadow to the title of the NavBar
ios, objective-c
Solution
You should use these keys for the shadow color and offset.
UITextAttributeTextShadowColor
UITextAttributeTextShadowOffset
There is no way to specify the shadow radius as a text attribute.
If you really wanted a custom shadow you could create your own `UILabel` and set the shadow like in your first example. Then you would set that label as the `titleView` of your view controllers `UINavigationItem`.
You would have to update the text yourself though (the navigation controller would no longer do it for you automatically).
Problem
I got a program from a colleague and he is using .xib files to setup his view. (being a hard core coder, I never used IB myself...) So he is setting up his ViewControler and he has a NavBar (that I could not find in the .xib file!). I want to add drop shadows to the title. If I was making the NavBar, the relative code would be something like: ``` textViewTitle.layer.shadowOpacity = 2.0; textViewTitle.layer.shadowRadius = 3.0; textViewTitle.layer.shadowOffset = CGSizeMake(2.0, 3.0); ``` and that works fine. Digging around I found that now I need to use this: ``` NSDictionary *navbarTtlAts = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], UITextAttributeTextColor, [UIColor blackColor], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(2.0, 3.0)], UITextAttributeTextShadowOffset, nil]; [self.navigationController.navigationBar setTitleTextAttributes:navbarTtlAts]; ``` Although this works, I could not find how to add the shadowOpacity & shadowRadius stuff. I found that I could add the following in the NSDictionary, but it did not work... ``` [NSNumber numberWithFloat: 2.0], @"shadowOpacity", [NSNumber numberWithFloat: 3.0], @"shadowRadius", ``` Any ideas?