解决方案
根据 @visualication 提出的想法,放入以下代码(放在 application:didFinishLaunchingWithOptions:
中)可以解决此问题:
[[[self navigationController] navigationBar] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], UITextAttributeTextShadowColor:[UIColor whiteColor], UITextAttributeTextShadowOffset:[NSValue valueWithUIOffset:UIOffsetMake(0, 0)]}];
iOS 6下的截图:
原帖
看一下iOS 6上的这个截图:
标题有一些黑色阴影,我没有编写阴影,我只是提供了背景图片,宽320点,高44点,颜色略带红色。
/// 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
使用以下代码将标题设置为导航栏:
/// Set the title
[[[self navigationController] topViewController] setTitle:@"dynamiclc2"];
上述标题设置代码在iOS 6中会产生阴影,但在iOS 7中不会产生阴影:
![enter image description here](https://istack.dev59.com/LaGTW.webp)
[[[self navigationController] navigationBar] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], UITextAttributeTextShadowColor:[UIColor whiteColor], UITextAttributeTextShadowOffset:[NSValue valueWithUIOffset:UIOffsetMake(0, 0)]}];
- GeorgeMKMailComposeViewController
期间崩溃。是否有其他方法可以克服这个问题? - Rugmangathan