现在,根据@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中不产生阴影:
我希望iOS 6中的导航栏标题显示与iOS 7版本相同(或几乎相同)。
您可以像这样设置阴影:
[[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]];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句