Customization of Tabbar

Source: Internet
Author: User

[Self createcustomtabbar];

-(void) createcustomtabbar{
Create a Uiimageview, as a basemap
Uiimageview *bgview = [[Uiimageview alloc] Initwithframe:cgrectmake (0,[uiscreen mainscreen].bounds.size.height-49, 320, 49)];
Bgview.image = [UIImage imagenamed:@ "Tabbg.png"];
Bgview.tag = 999;
Turn on interactive properties for ImageView
bgview.userinteractionenabled = YES;
[Self.view Addsubview:bgview];


Creating a button instance simulation Tabbaritem
Between each button
Nsarray *array=[nsarray arraywithobjects:@ "iconsettings", @ "Iconprofile", @ "Iconhome", @ "Iconempty", @ "IconCalendar" , @ "Btn_bottom1_on.png", @ "Btn_bottom2_on.png", @ "Btn_bottom3_on.png", @ "Btn_bottom4_on.png", @ "Btn_bottom5_on.png" , nil];
for (int i = 0; i< (array.count)/2; i++) {
NSString *imagename = [array objectatindex:i];
NSString *selectedimage = [array objectatindex:i+5];
UIButton *btn = [UIButton buttonwithtype:uibuttontypecustom];
[Btn Setframe:cgrectmake (0+64*i, 0, 64, 49)];
Set the background picture of the button in the general state
[btn Setbackgroundimage:[uiimage Imagenamed:imagename] forstate:uicontrolstatenormal];
Sets the background picture when the button is selected
[btn Setbackgroundimage:[uiimage imagenamed:selectedimage] forstate:uicontrolstateselected];
[Btn Addtarget:self
Action: @selector (btnclicked:) forcontrolevents:uicontroleventtouchupinside];
Btn.tag = i;

if (i==0) {
btn.selected = YES;
}

[Bgview ADDSUBVIEW:BTN];
}
}
-(void) btnclicked: (UIButton *) btn
{
Click on a different button to switch between different view controllers
Self.selectedindex = Btn.tag;
Toggle display status for different btn
Uiimageview *bgview = (Uiimageview *) [Self.view viewwithtag:999];
For (UIView *subview in bgview.subviews) {
if ([SubView Iskindofclass:[uibutton class]]) {
UIButton *BTN1 = (UIButton *) SubView;
if (Btn1.tag = = Btn.tag) {
btn1.selected = YES;
}else{
btn1.selected = NO;
}
}
}
}

Customization of Tabbar

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.