[英]How can I make the navigation bar on my iPhone app look metallic?
I don't know how my client mocked up their screenshots, but they ended up with an image where the navigation bar has a kind of two-tone metallic look, like this: 我不知道我的客户如何模拟他们的屏幕截图,但最终得到的图像是导航栏具有两色调金属外观的图像,如下所示:
But when I build the app, it ends up fading gradually from my tint colour towards white, like this: 但是,当我构建该应用程序时,它最终会从我的色彩逐渐变成白色,如下所示:
The trouble is, the clients really like the way it looks in their mock-up. 问题是,客户真的很喜欢它在模型中的外观。 What can I do?
我能做什么?
Subclass UINavigationBar
. 子类
UINavigationBar
。 In your subclass, override drawRect:
to custom-draw what you want. 在您的子类中,重写
drawRect:
以自定义绘制所需的内容。 In your instance of UINavigationController
, make sure the navigation bar is an instance of your subclass. 在您的
UINavigationController
实例中,确保导航栏是您的子类的实例。
If you're programmatically instantiating your navigation controller, you might not be able to do this--you may have to resort to adding a category to UINavigationBar
that overrides drawing for all instances: 如果您正在以编程方式实例化导航控制器,则可能无法执行此操作-您可能不得不向
UINavigationBar
添加类别,以覆盖所有实例的图形:
@implementation UINavigationBar (CustomDrawing)
- (void)drawRect: (CGRect)rect {
// ...
}
@end
It's also possible to use method swizzling to override UINavigationBar
's default behaviour, but explaining method swizzling is beyond the scope of this question. 也可以使用swizzling方法来覆盖
UINavigationBar
的默认行为,但是解释方法swizzling不在此问题的范围内。
On the heels of @Jonathan's answer Ray Wenderlich has a great tutorial on creating your own gradients. 在@Jonathan的回答之后, Ray Wenderlich提供了有关创建自己的渐变的出色教程。
Here's a snippit: 这是一个摘录:
void drawGlossAndGradient(CGContextRef context, CGRect rect, CGColorRef startColor,
CGColorRef endColor) {
drawLinearGradient(context, rect, startColor, endColor);
CGColorRef glossColor1 = [UIColor colorWithRed:1.0 green:1.0
blue:1.0 alpha:0.35].CGColor;
CGColorRef glossColor2 = [UIColor colorWithRed:1.0 green:1.0
blue:1.0 alpha:0.1].CGColor;
CGRect topHalf = CGRectMake(rect.origin.x, rect.origin.y,
rect.size.width, rect.size.height/2);
drawLinearGradient(context, topHalf, glossColor1, glossColor2);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.