xcode UITabBar 完全透明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9539203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:30:20  来源:igfitidea点击:

UITabBar fully transparent

iphoneiosxcodecocoatabbar

提问by Matthijn

In XCode I am using the interface builder (StoryBoard) to lay out most of my layout. However I want some custom drawing on this. This works quite well.

在 XCode 中,我使用界面构建器 (StoryBoard) 来布置我的大部分布局。但是我想要一些自定义绘图。这很有效。

There is however a problem what I am facing. I have a "bite" out of the active tab. (see http://cl.ly/Efno) I want this bite fully transparent. (I have set an pink background color to see what part I want transparent which is not transparent.)

然而,我面临着一个问题。我从活动标签中“咬了一口”。(见http://cl.ly/Efno)我想要这口完全透明。(我已经设置了一个粉红色的背景颜色,看看我想要透明的部分是不透明的。)

How I have changed the look and feel is the following.

我如何改变外观和感觉如下。

  • Set the UITabBar class to my own class in the interface builder for the corresponding tabbar.
  • In the awakeFromNib of that class I have set the label position and image and selected image of each tabbar item. Like so

    [tabBarItem setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:image];
    
  • 在相应标签栏的界面构建器中将 UITabBar 类设置为我自己的类。
  • 在该类的awakeFromNib 中,我设置了每个标签栏项目的标签位置和图像以及选定的图像。像这样

    [tabBarItem setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:image];
    

Each image fully covers the entire tabbar in height and has the width of the tab item itself.

每个图像在高度上完全覆盖整个标签栏,并具有标签项本身的宽度。

  • Set the background image of the tabbar to none (a fully transparent image)
  • Set the background color of the tabbar to a fully transparent color (now I have a pink color set to see where it goes wrong)
  • In the interface builder uncheck "opaque" for the tabbar.
  • 将标签栏的背景图像设置为无(完全透明的图像)
  • 将标签栏的背景颜色设置为完全透明的颜色(现在我设置了粉红色以查看哪里出错了)
  • 在界面构建器中,取消选中标签栏的“不透明”。

However, it is not transparent, the pink part is black. How can I make this transparent?

但是,它不是透明的,粉红色的部分是黑色的。我怎样才能使这个透明?

Thanks

谢谢

采纳答案by Wilmar

Have a look at the appearance proxy for UITabBar, you might be able to do what you want there without having to use a custom subclass. There are tons of properties you can access and change. You could set the relevant properties in the app delegate. It is iOS5 only though, but I gather that you are using that already, since you mentioned storyboards.

看看 UITabBar 的外观代理,您也许可以在那里做您想做的事,而不必使用自定义子类。您可以访问和更改大量属性。您可以在应用程序委托中设置相关属性。虽然它只是 iOS5,但我认为你已经在使用它了,因为你提到了故事板。

E.g.

例如

UIImage *tabBarBackground = [UIImage imageNamed:@"tabBarBackground.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:127.0/255.0 green:186.0/255.0 blue:235.0/255.0 alpha:1.0]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabBarItemSelected.png"]];