【问题标题】:Get the real color of the navigation bar获取导航栏的真实颜色
【发布时间】:2018-01-15 10:51:58
【问题描述】:

对于我在 iPhone X 上的应用,我需要创建一个页脚。这里没问题。

但是我需要把导航栏的颜色设置为相同

navigationBar 的颜色是在 barTintColor 上设置的,不能更改。

构建的应用程序,在导航栏上自动设置 UIVisualEffect 并且颜色更改:它更亮了。

如何获得导航栏显示的颜色?

我试过但没用:

  • footer.backgroundColor = [UIColor myColor]

  • footer.tintColor = [UIColor myColor]

  • footer.tintColor = navigationBar.barTintColor

  • footer.backgroundColor = navigationBar.barTintColor
  • imageView.image = [self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault]; [footer addSubview: imageView];

  • UIVisualEffect *blurEffect; blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; UIVisualEffectView* visualView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; [self.footer addSubview:visualView];

**导航栏代码:**

self.navigationController.navigationBar.barTintColor = tintColor;

[self.navigationController.navigationBar setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  [UIFont dpBoldFontWithSize:16.8],NSFontAttributeName,
  fontColor,NSForegroundColorAttributeName,
  nil]];
[self.navigationItem setTitle:title];

**页脚代码**

  self.footerView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - 35, self.view.width, 35)];

    [self.footerView setBackgroundColor:color];
    [self.view addSubview:self.footerView];

问题截图:

Screenshot

【问题讨论】:

  • 在页脚视图中添加 UIVisualEffectView 怎么样?
  • 我尝试了模糊效果StyleLight,但没有颜色变化
  • 嗯,您没有在此处设置visualView 的框架。你能添加一些代码或上下文吗?
  • 我加了一个框架,颜色没有变化
  • 使用 navigationBar.isTranslucent = false ?

标签: ios


【解决方案1】:

或者自动调整大小的掩码怎么样?

   UIView * footerView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 35, self.view.bounds.size.width, 35)];
    footerView.backgroundColor = UIColor.redColor;
    footerView.autoresizingMask = (UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth);
    [self.view addSubview:footerView];

【讨论】:

    猜你喜欢
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多