Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

iphone - How can I add a custom divider image to the UITabBar?

I have a UITabBar that I am trying to style after the new iOS 6 App Store look. I have some pretty good looking gradients, but I am wondering how to set the divider image.

Aside from manually adding the line to each image, is there anything I can do to reproduce the divider look?

enter image description here

enter image description here

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can add an image for each item , for the selected and unselected states. Like this:

    UIImage *selectedImage0     = [UIImage imageNamed:@"image1.png"];
    UIImage *unselectedImage0   = [UIImage imageNamed:@"image1_unselected.png"];

    UIImage *selectedImage1     = [UIImage imageNamed:@"image2.png"];
    UIImage *unselectedImage1   = [UIImage imageNamed:@"image2_unselected.png"];

    UIImage *selectedImage2     = [UIImage imageNamed:@"image3.png"];
    UIImage *unselectedImage2   = [UIImage imageNamed:@"image3_unselected.png"];

    UIImage *selectedImage3     = [UIImage imageNamed:@"image4.png"];
    UIImage *unselectedImage3   = [UIImage imageNamed:@"image4_unselected.png"];

    UIImage *selectedImage4     = [UIImage imageNamed:@"image5.png"];
    UIImage *unselectedImage4   = [UIImage imageNamed:@"image5_unselected.png"];

    UITabBar     *tabBar = self.tabBarController.tabBar;
    UITabBarItem *item0  = [tabBar.items objectAtIndex:0];
    UITabBarItem *item1  = [tabBar.items objectAtIndex:1];
    UITabBarItem *item2  = [tabBar.items objectAtIndex:2];
    UITabBarItem *item3  = [tabBar.items objectAtIndex:3];
    UITabBarItem *item4  = [tabBar.items objectAtIndex:4];

    [item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
    [item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
    [item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
    [item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
    [item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];

You can place this code in the viewDidLoad method of any of your controllers. Hope this helps.

Cheers!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...