2012-12-21 13 views
16

का उपयोग कर कस्टम छवियों द्वारा आईफोन टैब बार आइकन कैसे सेट करें Iphone विकास के लिए नौसिखिया हूं, मुझे टैब बार में एक कस्टम छवि आइकन डालना होगा। लेकिन यह केवल डिफ़ॉल्ट रंग दिखाता है (काला नीला)। मुझे इस बग दोस्तों से दूर करने के लिए ...?कहानी बोर्ड

+0

का उपयोग नहीं करने के लिए छवियों को जोड़ने के लिए मत भूलना कोडिंग UIImage – GaneshKumar

उत्तर

21

छवियाँ आवेदन में,

जोड़ सकते हैं और संलग्न छवि देखें

enter image description here

+0

चयनित छवियां wokring नहीं हैं .. मैंने इंस्पेक्टर की पहचान की और इंस्पेक्टर इंस्पेक्टर xcode> 6.1 – iosMentalist

6

viewDidLoad में इस कोड का प्रयोग करें

UIImage *selectedImage0 = [UIImage imageNamed:@"selected.png"]; 
UIImage *unselectedImage0 = [UIImage imageNamed:@"unselected.png"]; 

UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; 

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0]; 
+0

कहाँ से 'tabBar' चर मिलता है में यह कोशिश? – Siddharth

+3

यह विधि अब बहिष्कृत है। –

+0

@SalehMasum उस पर मेरा ध्यान आकर्षित करने के लिए धन्यवाद। यदि आप समाधान जानते हैं तो कृपया मेरा जवाब संपादित करें। मैं इसे स्वीकार करूंगा। – CRDave

2

आप टैब बार के एक कस्टम छवि (आइकन और पृष्ठभूमि) जोड़ना चाहते हैं और सिर्फ नीले चिह्न बदलने नहीं हैं:

लिए नीचे दिए गए कोड जोड़ें आपकी पहली UIView .m-file। यदि आप "टैब्ड एप्लिकेशन" प्रोजेक्ट के साथ ताज़ा शुरू करते हैं तो इसे FirstViewController.m कहा जाता है, छवियों को जोड़ने के लिए मत भूलना (और चेक मार्क 'गंतव्य समूह के फ़ोल्डर में आइटम कॉपी करें') सेट करें और छवियों के लिए बेहतर नाम चुनें ।

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

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

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

    UITabBar *tabBar = self.tabBarController.tabBar; 
    UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; 
    UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; 

    [item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0]; 
    [item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1]; 
} 

आप इस समाधान और अन्य महान ट्यूटोरियल की टन Ray Wenderlichs पृष्ठ पर के बारे में अधिक जानकारियां मिल सकती हैं।

4

AppDelegate में नीचे दिए गए कोड का प्रयोग करें

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 


UIViewController *viewController1 = [[ViewFirstViewController alloc] init]; 

UIViewController *viewController2 = [[ViewSecondViewController alloc] init]; 
UIViewController *viewController3 = [[ViewThirdViewController alloc] init]; 
UIViewController *viewController4 = [[ViewFourthViewController alloc] init]; 

self.tabBarController = [[UITabBarController alloc] init]; 
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,viewController3,viewController4, nil]; 
self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 


imgTab = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320.0,50)]; 
self.tabBarController.tabBar.tag=10; 
[self.tabBarController.tabBar addSubview:imgTab]; 
self.tabBarController.delegate = self; 

imghome=[[UIImageView alloc]initWithFrame:CGRectMake(0.0,00.0,80.0,50.0)]; 
imghome.image=[UIImage imageNamed:@"dressup_active.png"]; 
[imgTab addSubview:imghome]; 

imgQuiz=[[UIImageView alloc]initWithFrame:CGRectMake(80.0,00.0,81.0,50.0)]; 
imgQuiz.image=[UIImage imageNamed:@"x-mas_tree.png"]; 
[imgTab addSubview:imgQuiz]; 

imgtTW=[[UIImageView alloc]initWithFrame:CGRectMake(161.0,00.0,80.0,50.0)]; 
imgtTW.image=[UIImage imageNamed:@"greetings.png"]; 
[imgTab addSubview:imgtTW]; 

imgGuest=[[UIImageView alloc]initWithFrame:CGRectMake(241.0,00.0,80.0,50.0)]; 
imgGuest.image=[UIImage imageNamed:@"quotes_tab.png"]; 
[imgTab addSubview:imgGuest]; 

} 

tabBar नियंत्रक प्रतिनिधि विधि

- (void)tabBarController:(UITabBarController *)tabBarControllers didSelectViewController:(UIViewController *)viewController 
{ 

NSLog(@"%i",tabBarControllers.selectedIndex); 
if (tabBarControllers.selectedIndex == 0) 
{ 

    imghome.image=[UIImage imageNamed:@"dressup_active.png"]; 
    imgQuiz.image=[UIImage imageNamed:@"x-mas_tree.png"]; 
    imgtTW.image=[UIImage imageNamed:@"greetings.png"]; 
    imgGuest.image=[UIImage imageNamed:@"quotes_tab.png"]; 

} 
else if (tabBarControllers.selectedIndex == 1) 
{ 

    imghome.image=[UIImage imageNamed:@"dressup.png"]; 
    imgQuiz.image=[UIImage imageNamed:@"x-mas_tree_active.png"]; 
    imgtTW.image=[UIImage imageNamed:@"greetings.png"]; 
    imgGuest.image=[UIImage imageNamed:@"quotes_tab.png"]; 

} 
else if (tabBarControllers.selectedIndex == 2) 
{ 

    imghome.image=[UIImage imageNamed:@"dressup.png"]; 
    imgQuiz.image=[UIImage imageNamed:@"x-mas_tree.png"]; 
    imgtTW.image=[UIImage imageNamed:@"greetings_active.png"]; 
    imgGuest.image=[UIImage imageNamed:@"quotes_tab.png"]; 

} 
else if (tabBarControllers.selectedIndex == 3) 
{ 

    imghome.image=[UIImage imageNamed:@"dressup.png"]; 
    imgQuiz.image=[UIImage imageNamed:@"x-mas_tree.png"]; 
    imgtTW.image=[UIImage imageNamed:@"greetings.png"]; 
    imgGuest.image=[UIImage imageNamed:@"quotes_active.png"]; 

} 



} 
+0

आपको बहुत धन्यवाद दोस्त मैं इस धन्यवाद के लिए बिल्कुल खोज रहा था बहुत +1 – ashokdy

4

आप iOS7 के लिए इस कोड का उपयोग कर सकते हैं:

UIImage *iconBoxOffice = [UIImage imageNamed:@"box-office.png"]; 
UIImage *selectedIconBoxOffice = [UIImage imageNamed:@"selected-box-office.png"]; 
UIImage *iconDvds = [UIImage imageNamed:@"dvds.png"]; 
UIImage *selectedIconDvds = [UIImage imageNamed:@"dvds.png"]; 

UITabBar *tabBar = self.tabBarController.tabBar; 
UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; 
UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; 

[item0 initWithTitle:@"Box Office" image:iconBoxOffice selectedImage:selectedIconBoxOffice]; 
[item1 initWithTitle:@"Dvds" image:iconDvds selectedImage:selectedIconDvds]; 

यदि आप और अधिक टैब हैं आप और अधिक आइटम जोड़ने रख सकते हैं। * अपनी परियोजना * इस प्रोग्राम के रूप में किया जाता है, स्टोरीबोर्ड

संबंधित मुद्दे