简体   繁体   English

UITabBar完全透明

[英]UITabBar fully transparent

In XCode I am using the interface builder (StoryBoard) to lay out most of my layout. 在XCode中,我使用界面构建器(StoryBoard)来布局我的大部分布局。 However I want some custom drawing on this. 但是我想要一些自定义绘图。 This works quite well. 这非常有效。

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. (参见http://cl.ly/Efno )我希望这一口完全透明。 (I have set an pink background color to see what part I want transparent which is not transparent.) (我设置了一个粉红色的背景颜色,看看我想透明哪个部分不透明。)

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. 在相应的tabbar的界面构建器中将UITabBar类设置为我自己的类。
  • In the awakeFromNib of that class I have set the label position and image and selected image of each tabbar item. 在该类的awakeFromNib中,我设置了每个tabbar项的标签位置和图像以及所选图像。 Like so 像这样

     [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) 将tabbar的背景图像设置为none(完全透明的图像)
  • 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. 在界面构建器中,取消选中标签栏的“opaque”。

However, it is not transparent, the pink part is black. 但是,它不透明,粉红色部分是黑色的。 How can I make this transparent? 我该如何透明?

Thanks 谢谢

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. 看看UITabBar的外观代理,您可以在不使用自定义子类的情况下执行您想要的操作。 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. 虽然它只是iOS5,但我认为你已经使用了它,因为你提到了故事板。

Eg 例如

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"]];

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

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