Iphone 如何使我的导航栏和底部的工具栏成为单一颜色?
我有一个应用程序,其中我同时使用导航栏和工具栏(在底部)。两者都有一个从中心到底部的阴影。这就是我创建工具栏的方式`Iphone 如何使我的导航栏和底部的工具栏成为单一颜色?,iphone,ios,ipad,Iphone,Ios,Ipad,我有一个应用程序,其中我同时使用导航栏和工具栏(在底部)。两者都有一个从中心到底部的阴影。这就是我创建工具栏的方式` [self.navigationController setToolbarHidden:NO animated:YES]; self.navigationController.toolbar.barStyle = UIBarStyleBlackOpaque; self.navigationController.toolbar.frame=CGRectMak
[self.navigationController setToolbarHidden:NO animated:YES];
self.navigationController.toolbar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.toolbar.frame=CGRectMake(0, [[UIScreen mainScreen] bounds].size.height -12, [[UIScreen mainScreen] bounds].size.width,30);
self.navigationController.toolbar.tintColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"top_bar.png"]];
我正在这样做导航栏
UIImage *navBar = [UIImage imageNamed:@"top_bar.png"];
[[UINavigationBar appearance] setBackgroundImage:navBar forBarMetrics:UIBarMetricsDefault];
`有人能告诉我哪里出了问题吗?我认为最简单的方法是创建1x1 UIImage,然后将其设置为导航栏和工具栏的背景图像。这将消除渐变,使两个条成为您选择的一种纯色。下面是一个例子:
UIImage *image = [self imageWithColor:[UIColor redColor]];
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
[[UIToolbar appearance] setBackgroundImage:image forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
如果你想摆脱导航栏下面的阴影,这对我很有用:
[self.navigationController.navigationBar setClipsToBounds:YES];
你能显示你现在得到的结果吗?@NikitaPestrov你能检查一下我编辑的查询吗?我希望它是单色的。不要底部的阴影。为什么不创建带有渐变颜色的UIView,看起来像UINavigationBar。你得到的结果是什么?