定制UITabBar显示样式

来源:互联网 发布:淘宝化妆品品牌 编辑:程序博客网 时间:2024/03/29 21:53

定制UITabBar显示样式

 

思路是这样子的:

1. 初始化UITabBarController,并装载进来几个其他的ViewController

2. 获取每个控制器的UITabBarItem

3. 单独配置每个ViewController对应的UITabBarItem(其中,文字可以设置偏移量)

就这么简单哦!

 

 

 

问:如何设置UITabBarController高亮选中的颜色值呢?

 

问:[UITabBar appearance]能干什么?

他是进行UITabBarController全局设定的,也就是说不需要你一个一个的单独设定.

http://www.altinkonline.nl/tutorials/xcode/uitabbar/customizing-background-tintcolor-and-selected-image/

To customize the UITabBar you must have an referrer to the UITabBarController.

Open your class wich refers to the UITabBarController. Add the code below in your class. E.g. in the viewDidLoad: method.

Customize the UITabBar by setting the backgroundimage of your UITabBar.

    UIImage *tabBackground = [[UIImage imageNamed:@"tabBarBackground.jpg"]                               resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];    // Set background for all UITabBars    [[UITabBar appearance] setBackgroundImage:tabBackground];    // Set background for only this UITabBar    [[tabBarController tabBar] setBackgroundImage:tabBackground];

Customize the UITabBar by setting the tintColor for the images.

    // Set tint color for the images only for this tabbar    [[tabBarController tabBar] setSelectedImageTintColor:[UIColor brownColor]];    [[tabBarController tabBar] setTintColor:[UIColor whiteColor]];    // Set tint color for the images for all tabbars    [[UITabBar appearance] setSelectedImageTintColor:[UIColor brownColor]];    [[UITabBar appearance] setTintColor:[UIColor whiteColor]];

Customize the UITabBar by setting the selectionIndicatorImage.

    // Set selectionIndicatorImage for this tabbar    [[tabBarController tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"selectedtab.png"]];    // Set selectionIndicatorImage for all tabbars    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selectedtab.png"]];

Now you've an full customized UITabBar!

 

问:UITabBar的图片尺寸是多少呢?

icon为 60x60pix 的png图片,使用时请用如下格式(如图片名字为 newDay@2x, 使用时直接使用名字即可)

 

问:如何隐藏UITabBar上的那条黑线?

[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"tm.png"]];

The shadow image to be used for the tab bar.
The default value is nil, which corresponds to the default shadow image. When non-nil, this property represents a custom shadow image to show instead of the default. For a custom shadow image to be shown, a custom background image must also be set using the backgroundImage property. If the default background image is used, then the default shadow image will be used regardless of the value of this property.

根据这个描述信息来看,如果设定了setShadowImage,那也必须设定背景图片哦.

 

附录:

1. 样式

 

2. 一些尺寸

 

 

0 0
原创粉丝点击