如何在iOS 7中为半透明导航栏添加正确的 colored颜色 ?导航栏只是将给定的 colored颜色 调整为更亮的 colored颜色 .更改 colored颜色 的亮度或饱和度也不会产生正确的效果.

有人有同样的问题吗?看看Facebook,它似乎有点用:它们有自己的 colored颜色 和半透明的导航栏.

编辑:只是想说明一下:我需要条形图是半透明的,不是透明的(有一些Alpha),不是实心的!http://en.wikipedia.org/wiki/Transparency_and_translucency

编辑:现在发布到Apple BugReporter

推荐答案

该条将调整您的 colored颜色 值.

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

你可以使用这个计算器,在屏幕上渲染时输入你想要的 colored颜色 ,它会告诉你设置条TintColor的 colored颜色 ,这样当Apple调整它时,它就会显示为预期的 colored颜色

https://www.transpire.com/insights/blog/bar-color-calculator/

编辑:请注意,这些计算是针对白色背景和较浅的 colored颜色 (RGB超过40,如果您需要更深的 colored颜色 ,您将需要添加一个背景层,就像其他人提到的那样-尽管这会减少条形图的模糊)

深度指南: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]];

Ios相关问答推荐

为什么controlSize属性在SwiftUI中不起作用?

Flutter应用程序无法使用IOS/Swift的蓝牙核心库发现某些外围设备

如何保持拖动预览与原始项目完全相同?

不使用iOS 17修改器修改SWIFT用户界面视图

Swift导航远离视频导致崩溃

如何删除NavigationView中的默认透明标头?

如何在 Android 上的 Flutter 应用中录制内部音频?

仅更改 AttributedString 的字符串(例如 UIButton 配置 attributeTitle)

不可发送类型 '[String : Any]?'在调用非隔离实例方法 XXX 时退出主参与者隔离上下文不能跨越参与者边界

使用 JSONDecoder 解码的对象的打印输出有问题

Flutter firebase_auth 中的无效应用程序凭据/令牌不匹配

SwiftUI 中的描边图像边框

Text() 正在添加额外的前导尾随填充 SwiftUI

通过函数使用 Gesture 时,键入任何视图不能符合视图

ARKit vs. ARCore vs. Vuforia vs. D'Fusion Mobile vs. Layar SDK

通过 iOS 创建和导出动画 gif?

如何在 iPhone 中为透明的 PNG 图像着色?

有没有办法在应用store 之外分发 ios 应用程序?

iTunes Connect 中的无限制 Web 访问是什么意思

iPhone:什么是 WWDR 中级证书?