【问题标题】:Completely transparent UITabBar in iOS 8iOS 8 中完全透明的 UITabBar
【发布时间】:2014-10-09 13:19:09
【问题描述】:

我正在尝试使我的 tabBar 透明,我已经搜索过,但我发现的只是导致部分透明和不完全透明的 tabBar 的文章,有些是针对 IOS 5 等的。

我想像 Sketch 3 中看到的那样完成这个:

最简单的方法是什么?

我想过这样做:

    // Make the tabBar transparent
self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
self.tabBarController.tabBar.translucent = YES;

但结果并不完美:

非常感谢帮助!:)

真诚地, 埃里克

更新

// Make the tabBar transparent
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
self.tabBarController.tabBar.translucent = YES;

【问题讨论】:

    标签: ios objective-c uitabbarcontroller uitabbar transparent


    【解决方案1】:

    你试过barTintColor吗?

    [[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
    [[UITabBar appearance] setBackgroundImage:[UIImage new]];
    

    这应该可以解决问题。

    【讨论】:

    • 与我在更新问题中输入的代码结果相同:/ - 我将此代码放入 viewWillAppear 方法中,对吗?
    • @Erik viewWillAppear: 为时已晚。尝试将其放入您的 AppDelegate 的 application:didFinishLaunchingWithOptions: 中,看看是否有帮助。
    • @JohannesFagrenkrug 不幸的是,结果与我用 didFinishLaunchingWithOptions 编写的更新中的代码相同:
    • 你节省了我很多时间。
    • 我将它与 Lior 的回答结合使用,setShadowImage 是让黑线消失的诀窍。
    【解决方案2】:

    Swift 3.0

    ...在AppDelegate的didFinishLaunchingWithOptions中调用这段代码

    let tabBar = UITabBar.appearance()
    tabBar.barTintColor = UIColor.clear
    tabBar.backgroundImage = UIImage()
    tabBar.shadowImage = UIImage()
    

    结果将是每个 UITabBar 的透明背景。

    【讨论】:

    • 在互联网上多次尝试不同的事物和解决方案之后,这使得标签栏“半透明”,但现在感觉它太半透明了,根本没有模糊。我相信是导致这种情况的 tabBar.backgroundImage = UIImage() 。是否有任何额外的帮助可以产生漂亮的模糊效果而不是完全透明?
    【解决方案3】:

    您需要继承 UITabBarController 并在 viewdidload: 中放置以下代码:

    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContextWithOptions(rect.size, NO, 1.0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextFillRect(context, rect);
    UIImage *transparentImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.tabBar setBackgroundImage:transparentImage];
    [self.tabBar setShadowImage:transparentImage];    
    //    self.tabBar.alpha = 0.0;
    

    【讨论】:

    • 我没有使用子类,但setShadowImage 是我的问题的秘密,+1 :)
    猜你喜欢
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 2018-11-02
    • 1970-01-01
    相关资源
    最近更新 更多