UITabBar完全透明 [英] UITabBar fully transparent
问题描述
在XCode我使用界面构建器(StoryBoard)来布局我的大部分布局。但是我想要一些自定义绘图。这工作相当好。
然而,我面临的一个问题。我有一个咬出活跃的选项卡。 (请参见 http://cl.ly/Efno )我希望这个咬完全透明。 (我设置了一个粉红色的背景颜色,看看什么部分,我想透明不透明。)
我改变了外观和感觉是以下。
- 在界面构建器中为相应的Tabbar设置UITabBar类为我自己的类。
-
在该类的awakeFromNib中,我已设置标签位置和图像以及每个标签栏项目的选定图像。像这样
[tabBarItem setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:image];
每张图片完全覆盖整个Tabbar
- 将标签栏的背景图片设置为无(完全透明的图片)
- 将标签栏的背景颜色设置为完全透明的颜色(现在我有一个粉红色的颜色设置,看看它出错了)
- 取消选中标签栏的opaque。
但是,它不透明,粉红色部分为黑色。
感谢
看看UITabBar的外观代理,你可能能够做你想要的,而不必使用自定义子类。有大量的属性,你可以访问和更改。您可以在应用程式委托中设定相关的属性。
例如
pre> 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]];
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.
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.)
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];
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
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.
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"]];
这篇关于UITabBar完全透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!