1

我已经上网大约一个小时了,试图找到不同的方法来设置我的标签栏上的自定义图像。我正在使用调整大小的类。如果UIImage+ProportionalFill有人熟悉它。AppDelegate.h我对 Objective-C 有点陌生,我对使用这里的代码知之甚少。随意撕我一个新的,因为我确信它可能会是一个菜鸟的错误。

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

// [UIApplication sharedApplication].idleTimerDisabled = YES;
[application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
[[UITabBar appearance] setBackgroundColor:[UIColor colorWithRed:0/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]];
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];
UITabBarItem *tabBarItem5 = [tabBar.items objectAtIndex:4];

UIImage *oldProfile= [UIImage imageNamed:@"profile.png"];
UIImage *oldFeed = [UIImage imageNamed:@"feed.png"];
UIImage *oldSearch = [UIImage imageNamed:@"search.png"];
UIImage *oldNotifications = [UIImage imageNamed:@"notification.png"];
UIImage *oldMap = [UIImage imageNamed:@"compass.png"];
UIImage *newProfile;
UIImage *newFeed;
UIImage *newSearch;
UIImage *newNotifications;
UIImage *newMap;
CGSize newSize = CGSizeMake(30, 30);
newProfile = [oldProfile imageScaledToFitSize:newSize];
newFeed = [oldFeed imageScaledToFitSize:newSize];
newSearch = [oldSearch imageScaledToFitSize:newSize];
newNotifications = [oldNotifications imageScaledToFitSize:newSize];
newMap = [oldMap imageScaledToFitSize:newSize];

[tabBarItem1 setFinishedSelectedImage:newFeed withFinishedUnselectedImage:newFeed];
[tabBarItem2 setFinishedSelectedImage:newMap withFinishedUnselectedImage:newMap];
[tabBarItem3 setFinishedSelectedImage:newSearch withFinishedUnselectedImage:newSearch];
[tabBarItem4 setFinishedSelectedImage:newNotifications withFinishedUnselectedImage:newNotifications];
[tabBarItem5 setFinishedSelectedImage:newProfile withFinishedUnselectedImage:newProfile];

// Override point for customization after application launch.
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
return YES;
}  

编辑我收到的错误是:

 -[UINavigationController tabBar]: unrecognized selector sent to instance

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-       [UINavigationController tabBar]: unrecognized selector sent to instance
`
4

1 回答 1

1

参考以下链接:

https://github.com/boctor/idev-recipes

在上面的链接中没有示例,并且有一个“CustomTabBar”文件夹。在该示例中,实现了自定义标签栏。

于 2013-07-20T05:35:43.930 回答