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

查看:18
本文介绍了在 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.

只是为了清楚起见:我需要 Bar 是半透明的,不透明的(带有一些 alpha),而不是实心的!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,会产生最大的模糊

您可以使用此计算器并在屏幕上渲染时输入您想要的颜色,它会告诉您设置 barTintColor 的颜色,以便当 Apple 调整它时,它会按预期显示

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

https://www.transpire.com/insights/blog/条形颜色计算器/

请注意,这些计算适用于白色背景和较浅的颜色(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)

深入指南:https://www.transpire.com/insights/blog/custom-ui-navigationbar-colors-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

.

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天全站免登陆