[英]Tabbar icons pixelated
使用此代碼
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
tabBarItem1.title = @"Home";
tabBarItem2.title = @"Maps";
tabBarItem3.title = @"My Plan";
tabBarItem4.title = @"Settings";
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"home_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"home.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"maps_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"maps.png"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"myplan_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"myplan.png"]];
[tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"settings_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"settings.png"]];
工作正常。但是,當我使用此圖像時,在實際的iPhone測試中它看起來像是像素化的。使用較大的圖像(在寬度和高度上)將不合適,因為只能看到其中的一部分。 有沒有辦法將這些較大的圖像拉伸到特定的寬度和高度,以便可以看到其整個部分?
遵循《 iOS人機界面指南》中概述的尺寸。 另外,請不要指定.png,因為您希望能夠考慮非視網膜和視網膜圖像(w / @ 2x)。
在iOS 6或更早版本中,如果要創建32x32尺寸的按鈕,則需要使用這些像素尺寸制作PNG,並將其命名為Button.png
然后,當視網膜屏幕出現時,您開始需要制作2個素材資源Button.png和Button @ 2x.png,@ 2x素材資源為64x64像素。
使用iOS7及更高版本,無需同時使用這兩種資產。 您只需使用視網膜@ 2x資產。
將所有圖像資產放入資產目錄將使此操作變得更加容易。 因此,當您使用代碼中的@ 2x資產時,不應編寫.png擴展名。
例如:
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"home_selected"]...
注意:當您從情節提要中引用資產@ 2x資產時,只寫資產名稱而不使用@ 2x。
例如:對於您的名為home_selected@2x.png
的文件,在StoryBoard
您應編寫home_selected.png
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.