在iOS7半透明导航栏中获取正确的颜色 [英] Get the right color in iOS7 translucent navigation bar

查看:183
本文介绍了在iOS7半透明导航栏中获取正确的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS 7中为我的半透明导航栏获得正确的颜色?导航栏只是调整给定的颜色更明亮一个。改变颜色的亮度或饱和度也不会产生正确的结果。

How can I get the right coloring for my translucent navigation bars in iOS 7? The navigation bar just adjusts the given color to a much brighter one. Changing brightness or saturation of the color also doesn´t deliver the right result.

任何人有同样的麻烦吗?它似乎以某种方式工作,看着Facebook:他们有他们的颜色和半透明的导航栏。

Anyone having the same trouble? It seems to work somehow, looking at Facebook: they´re having their colors and translucent navigation bars.

编辑:只是为了清楚:我需要酒吧半透明,不透明(有一些阿尔法),不坚实! http://en.wikipedia.org/wiki/Transparency_and_translucency

Just to make it clear: I need the Bar to be translucent, not transparent (with some alpha), not solid! http://en.wikipedia.org/wiki/Transparency_and_translucency

编辑:现在发布到Apple BugReporter

Now posted to Apple BugReporter

推荐答案

该栏会调整您的颜色值。

The bar will adjust your color values.

首选方法,仅适用于RGB> = 40,会产生最模糊

Preferred method, for RGB >= 40 only, will give the most blurring

你可以使用这个计算器,并在屏幕上呈现你想要的颜色,它会告诉你什么设置barTintColor的颜色,所以当苹果调整它,它会显示预期

You can use this calculator and put in what you want the color to be when rendered on screen, it will tell you what to set the color of the barTintColor so when Apple adjusts it, it will show as intended

http:// b2cloud.com.au/how-to-guides/bar-color-calculator-for-ios7-and-ios8/

编辑:请注意,计算是为白色背景,而对于较浅的颜色(rgb超过40,如果你需要更暗,你将需要添加一个像其他人提到的背景层 - 虽然这将减少酒吧的模糊)

Note that these calculations are for a white background, and for lighter colours (rgb over 40, if you need darker, you will need to add a background layer like others have mentioned - although that will reduce the bar's blur)

/img707.imageshack.us/img707/3151/482w.png\">http://img707.imageshack.us/img707/3151/482w.png

深度指南: http://b2cloud.com.au/how- to-guides / custom-uinavigationbar-colors-in-ios7

片段:

@interface UnderlayNavigationBar : UINavigationBar

@end



.

@interface UnderlayNavigationBar ()
{
    UIView* _underlayView;
}

- (UIView*) underlayView;

@end

@implementation UnderlayNavigationBar

- (void) didAddSubview:(UIView *)subview
{
    [super didAddSubview:subview];

    if(subview != _underlayView)
    {
        UIView* underlayView = self.underlayView;
        [underlayView removeFromSuperview];
        [self insertSubview:underlayView atIndex:1];
    }
}

- (UIView*) underlayView
{
    if(_underlayView == nil)
    {
        const CGFloat statusBarHeight = 20;    //  Make this dynamic in your own code...
        const CGSize selfSize = self.frame.size;

        _underlayView = [[UIView alloc] initWithFrame:CGRectMake(0, -statusBarHeight, selfSize.width, selfSize.height + statusBarHeight)];
        [_underlayView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
        [_underlayView setBackgroundColor:[UIColor colorWithRed:0.0f green:0.34f blue:0.62f alpha:1.0f]];
        [_underlayView setAlpha:0.36f];
        [_underlayView setUserInteractionEnabled:NO];
    }

    return _underlayView;
}

@end

b
$ b

.

UIViewController* rootViewController = ...;
UINavigationController* navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[UnderlayNavigationBar class] toolbarClass:nil];
[navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:0.0f green:0.0f blue:90.0f/255.0f alpha:1]];
[navigationController setViewControllers:@[rootViewController]];

这篇关于在iOS7半透明导航栏中获取正确的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆