简体   繁体   English

透明的UITabBar

[英]Transparent UITabBar

I have subclassed UITabBar and I need it to be transparent. 我已经将UITabBar子类化了,我需要它是透明的。 Like This: 像这样: 在此输入图像描述

I have tried : [[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:79.0f/255.0 green:53.0f/255.0 blue:98.0f/255.0 alpha:0.6f]]; 我试过了: [[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:79.0f/255.0 green:53.0f/255.0 blue:98.0f/255.0 alpha:0.6f]];

It only changed The bar's color, but The bar is still not transparent. 它只改变了条形图的颜色,但条形图仍然不透明。

Please help. 请帮忙。 I have tried lots of different methods, but none of them worked. 我尝试过很多不同的方法,但都没有。

Try this 尝试这个

//  The color you want the tab bar to be
UIColor *barColor = [UIColor colorWithRed:79.0f/255.0 green:53.0f/255.0 blue:98.0f/255.0 alpha:0.6f];

//  Create a 1x1 image from this color
UIGraphicsBeginImageContext(CGSizeMake(1, 1));
[barColor set];
UIRectFill(CGRectMake(0, 0, 1, 1));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//  Apply it to the tab bar
[[UITabBar appearance] setBackgroundImage:image];

Here's the result 这是结果

在此输入图像描述

Here is a solution based on AnupamChugh's answer 这是基于AnupamChugh的答案的解决方案

  1. Create an IBOutlet for the tab bar in the UITabBarController 为UITabBarController中的选项卡栏创建一个IBOutlet
  2. Use that to set the tab bar as transparent 使用它将标签栏设置为透明

     class AppTabBarController: UITabBarController { @IBOutlet weak var mTabBar: UITabBar! override func viewDidLoad() { super.viewDidLoad() mTabBar.backgroundColor = UIColor.clear mTabBar.backgroundImage = UIImage() mTabBar.shadowImage = UIImage() // removes the border 

在此输入图像描述

UITabBar.appearance().backgroundColor=UIColor.clearColor()
UITabBar.backgroundImage = UIImage()

This kind of design is the default since iOS7. 这种设计是iOS7以来的默认设计。 Try this: 尝试这个:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM