我试图重新创建一个UINavigationBar的外观。栏的背景是使用渐变绘制的,但尚不清楚默认颜色和点的内容。有人在这方面做过什么吗?UINavigationBar渐变细节
回答
从我的一个项目。根据自己的喜好调整颜色。它还可以显示背景图片,如果你想(ImageReady中),否则它绘制导航栏像苹果的
// #Lighter r,g,b,a #Darker r,g,b,a
#define MAIN_COLOR_COMPONENTS { 0.153, 0.306, 0.553, 1.0, 0.122, 0.247, 0.482, 1.0 }
#define LIGHT_COLOR_COMPONENTS { 0.478, 0.573, 0.725, 1.0, 0.216, 0.357, 0.584, 1.0 }
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
if (imageReady) {
UIImage *img = [UIImage imageNamed: @"navigation_background.png"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
} else {
// Render yourself instead.
// You will need to adjust the MAIN_COLOR_COMPONENTS and LIGHT_COLOR_COMPONENTS to match your app
// emulate the tint colored bar
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat locations[2] = { 0.0, 1.0 };
CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
CGFloat topComponents[8] = LIGHT_COLOR_COMPONENTS;
CGGradientRef topGradient = CGGradientCreateWithColorComponents(myColorspace, topComponents, locations, 2);
CGContextDrawLinearGradient(context, topGradient, CGPointMake(0, 0), CGPointMake(0,self.frame.size.height/2), 0);
CGGradientRelease(topGradient);
CGFloat botComponents[8] = MAIN_COLOR_COMPONENTS;
CGGradientRef botGradient = CGGradientCreateWithColorComponents(myColorspace, botComponents, locations, 2);
CGContextDrawLinearGradient(context, botGradient,
CGPointMake(0,self.frame.size.height/2), CGPointMake(0, self.frame.size.height), 0);
CGGradientRelease(botGradient);
CGColorSpaceRelease(myColorspace);
// top Line
CGContextSetRGBStrokeColor(context, 1, 1, 1, 1.0);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, self.frame.size.width, 0);
CGContextStrokePath(context);
// bottom line
CGContextSetRGBStrokeColor(context, 0, 0, 0, 1.0);
CGContextMoveToPoint(context, 0, self.frame.size.height);
CGContextAddLineToPoint(context, self.frame.size.width, self.frame.size.height);
CGContextStrokePath(context);
}
}
@end
这比单梯度(我以前使用的),但是,甚至更好调整颜色后,仍然看起来不正确。 – 2009-12-06 04:40:32
你比我有更好的视力......我对这些结果感到满意。什么似乎关闭? – coneybeare 2009-12-06 05:36:17
我将深入探讨这一点,看看为什么它看起来不合我的眼力,但它比我考虑的回答要好得多。谢谢! – 2010-01-02 16:10:57
- 1. 删除UINavigationBar上的渐变
- 2. 如何复制UINavigationBar的渐变颜色?
- 3. UINavigationBar详细文本标签
- 4. 如何在Xamarin表单中添加渐变工具栏和UINavigationBar
- 5. 如何在UINavigationBar上应用渐变颜色?
- 6. 向我的UINavigationBar的后退按钮添加渐变
- 7. UINavigationBar与图像和默认渐变背景与iOS5
- 8. 改变UINavigationBar的
- 9. Android渐变背景渐变为透明
- 10. Mozilla渐变到其他渐变
- 11. -webkit渐变中的堆栈渐变
- 12. Dynamiclly在一个圆上渐变渐变
- 13. 渐变背景上的文字渐变
- 14. 带渐变神器的Android渐变
- 15. jQuery将图像渐变渐变为0
- 16. 改变颜色的细节视图
- 17. CSS3渐变人云亦云细线一堆倍
- 18. 渐变样式
- 19. 渐变背景
- 20. Tensorflow渐变
- 21. 绘制渐变
- 22. 画布渐变
- 23. imagick |渐变图
- 24. 垂直渐变
- 25. 一个渐变
- 26. 渐变是零
- 27. 渐变叠加
- 28. UIImage渐变
- 29. 从细节表
- 30. SLA细节bluemix
事实证明,它不是一个梯度,而是一种叠加透明图像。看到这个答案的细节http://stackoverflow.com/questions/15304629/how-can-i-replicate-uinavigationbars-gradient-colors – 2013-08-15 20:37:39