-2

这就是它的样子我有一个应用程序,我在其中同时使用导航栏和工具栏(在底部)。两者都有从中心到底部的阴影。这就是我创建工具栏的方式`

 [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"]];

and i am doing the navigation bar like this

 UIImage *navBar = [UIImage imageNamed:@"top_bar.png"];

    [[UINavigationBar appearance] setBackgroundImage:navBar forBarMetrics:UIBarMetricsDefault];

` 谁能指出我哪里出错了?

4

1 回答 1

1

我认为最简单的方法是创建一个 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];
于 2013-08-10T13:14:40.513 回答