我試圖重新創建一個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