IOS Sets the tab Bar in Tabviewcontroller and implements the custom

Source: Internet
Author: User

Development environment: Xcode 6.1 iOS 7.1.2 & iOS 8.1

Implement function One, the third tab corresponding view is displayed when the app is opened;

Implement function Two, set the picture for each tab and select the picture.

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {    Override point for customization after application launch.        ---------------------------------------------    //Set the first view as Camera view and custom tab bar    //------- --------------------------------------    [self settabbar];}

Implement Settab Bar:
---------------------------------------------#pragma mark-tab bar//-------------------------------------------    ---(void) settabbar{Uitabbarcontroller *tabviewcontroller = (Uitabbarcontroller *) Self.window.rootViewController;    [Tabviewcontroller Setselectedindex:2];    Uitabbar *tabbar = Tabviewcontroller.tabbar;        [TabBar settintcolor: [Uicolor Greencolor]];    First Uitabbaritem *tabbaritem1 = [Tabbar.items objectatindex:0];    uiimage* tabbaritem1image = [UIImage imagenamed:@ "XXX"]; UIImage *scaledtabbaritem1image = [UIImage imagewithcgimage:[tabbaritem1image cgimage] Scale: (Tabbaritem1image.scale    * 3) Orientation: (tabbaritem1image.imageorientation)];    uiimage* tabbaritem1selectedimage = [UIImage imagenamed:@ "XXX"]; UIImage *scaledtabbaritem1selectedimage = [UIImage imagewithcgimage:[tabbaritem1selectedimage cgimage] Scale: (    Tabbaritem1selectedimage.scale * 3) Orientation: (tabbaritem1selectedimage.imageorientation)]; (void) [TabBarItem1 initwithtitle:@]First "Image:scaledtabbaritem1image Selectedimage:scaledtabbaritem1selectedimage];    Second Uitabbaritem *tabbaritem2 = [Tabbar.items objectatindex:1];    uiimage* tabbaritem2image = [UIImage imagenamed:@ "XXX"]; UIImage *scaledtabbaritem2image = [UIImage imagewithcgimage:[tabbaritem2image cgimage] Scale: (Tabbaritem2image.scale    * 3) Orientation: (tabbaritem2image.imageorientation)];    uiimage* tabbaritem2selectedimage = [UIImage imagenamed:@ "XXX"]; UIImage *scaledtabbaritem2selectedimage = [UIImage imagewithcgimage:[tabbaritem2selectedimage cgimage] Scale: (    Tabbaritem2selectedimage.scale * 3) Orientation: (tabbaritem2selectedimage.imageorientation)]; (void)        [TabBarItem2 initwithtitle:@ "Second" Image:scaledtabbaritem2image selectedimage:scaledtabbaritem2selectedimage]; and Others Tabs-the same way}

in the didfinishlaunchingwithoptions a custom jump directly to a tab:

    Uitabbarcontroller *tabviewcontroller = (Uitabbarcontroller *) Self.window.rootViewController;    [Tabviewcontroller Setselectedindex:2];

To keep the pixels sharp, make the icons clearer, use large pictures, and then use the code to narrow them down:

[UIImage imagewithcgimage:[tabbaritem1image Cgimage] Scale: (Tabbaritem1image.scale * 3) Orientation: ( Tabbaritem1image.imageorientation)];
another:

Because the selected image system will always set the picture to tint color, the default is blue, so you need to set your own color:

[TabBar settintcolor: [Uicolor Greencolor]];


Reference Links:

Http://stackoverflow.com/questions/18894985/uitabbar-not-showing-selected-item-images-in-ios-7

http://stackoverflow.com/a/19386156/3458781

http://www.appcoda.com/ios-programming-how-to-customize-tab-bar-background-appearance/

IOS Sets the tab Bar in Tabviewcontroller and implements the custom

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.