gpt4 book ai didi

当我设置 BarTintColor 时,iOS 导航栏失去透明度

转载 作者:行者123 更新时间:2023-12-01 16:35:17 24 4
gpt4 key购买 nike

我对 iOS 开发相当陌生,并且最近几天一直在为创建具有自定义色调的半透明导航栏而烦恼。

我现在的状态:

  • 我创建了一个新项目,在导航 View 中嵌入了一个红色 View ,该导航 View 嵌入在选项卡栏中。
  • 在红色 View 中,我将图像部分放置在导航 View 后面,以证明半透明正在起作用。有用。
  • 我将条形颜色更改为白色:
    [[UINavigationBar appearance] setBarTintColor: [UIColor whiteColor]];
  • 透明感消失了。图像不再发光。所以我尝试了:
    [[UINavigationBar appearance] setBarTintColor: [[UIColor whiteColor] colorWithAlphaComponent: 0.5]];
  • 还是行不通。

  • 关于如何解决这个问题的任何建议?
    谢谢。

    最佳答案

    如果您只希望导航栏的背景是半透明的,您可以尝试:

    [(UIView*)[self.navigationController.navigationBar.subviews objectAtIndex:0] setAlpha:0.5f];

    我在这里找到了这个: https://stackoverflow.com/a/12389579/3626094

    否则,如果您希望整个导航栏是半透明的,包括按钮和标题,您可以尝试:
    self.navigationController.navigationBar.tintColor = [UIColor blueColor];
    self.navigationController.navigationBar.alpha = 0.5f;
    self.navigationController.navigationBar.translucent = YES;

    我在这里找到了这个: https://stackoverflow.com/a/6959527/3626094

    关于当我设置 BarTintColor 时,iOS 导航栏失去透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28875932/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com