Jestem początkującym programistą dla iPhone'a, potrzebuję umieścić niestandardową ikonę obrazu na pasku kart. Ale pokazuję tylko domyślny kolor (Czarny & niebieski) .Pomoc do pokonania z tymi przyjaciółmi błędów ...?jak ustawić ikonę paska zakładek iPhone'a za pomocą niestandardowych obrazów przy użyciu tablicy opowieści
Odpowiedz
dodać obrazy w aplikacji
i patrz załączony obrazu
wybrane obrazy nie są wokring .. próbowałem od inspektora identyfikacji i atrybut inspektor xcode> 6.1 – iosMentalist
użyć tego kodu w viewDidLoad
UIImage *selectedImage0 = [UIImage imageNamed:@"selected.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"unselected.png"];
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
Jeśli chcesz dodać własny obraz (ikony i tła) na pasku kart, a nie tylko zmienić niebieską ikonę:
Dodaj poniższy kod do twój pierwszy plik .m-UIView. Po uruchomieniu nowego projektu "Aplikacja z kartami" nazywa się FirstViewController.m Nie zapomnij dodać obrazów (i ustaw znacznik wyboru "Kopiuj elementy do folderu grupy docelowej") do projektu i wybierz lepsze nazwy dla obrazów .
- (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];
}
można znaleźć więcej informacji na temat tego rozwiązania i mnóstwo innych świetnych tutoriali na Ray Wenderlichs stronie.
skorzystać z poniższego kodu w 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];
}
metoda delegat umieszczenie zakładek Controller
- (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"];
}
}
dziękuję bardzo koleś szukałem właśnie za to dziękuję bardzo +1 – ashokdy
Można użyć tego fragmentu kodu do 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];
Możesz zachować dodając więcej przedmiotów, jeśli masz więcej kart. * nie zapomnij dodać obrazów do projektu * robi się to programowo, nie używając scenorysów
spróbuj w kodowaniu UIImage – GaneshKumar