Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 未选中时设置Abbaricon色调_Iphone_Objective C_Uitabbaritem - Fatal编程技术网

Iphone 未选中时设置Abbaricon色调

Iphone 未选中时设置Abbaricon色调,iphone,objective-c,uitabbaritem,Iphone,Objective C,Uitabbaritem,我正在尝试设置Uitabritem的图标,但它不起作用。顺便说一下,我在这个项目中使用的是Xcode 5 Beta版 @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { { [[UITabBarItem appearance] setTitleTe

我正在尝试设置Uitabritem的图标,但它不起作用。顺便说一下,我在这个项目中使用的是Xcode 5 Beta版

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    {
        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
        UIImage *tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
        [[UITabBar appearance] setBackgroundImage:tabBarBackground];
        [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]];
        [[UITabBar appearance] setTintColor:[UIColor whiteColor]];
    }
    return YES;
}

我试图让图标在选中和未选中时都是白色的,但在未选中状态下它们仍然是灰色的


编辑 我尝试过这样做,但现在我得到了错误“表达式结果未使用”


tintColor
设置背景的着色颜色,如果使用自定义背景图像,则无法看到此颜色。如果你不想有系统默认梯度,你必须使用和设置你的白色图像为他们两个

像这样:

UIImage *selectedImage = ...
UIImage *unselectedImage = selectedImage;
[tabBarItem setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
如果要在故事板中设置这些图像,则可以迭代现有UITabbaritem并更改其图像

将类似的内容放入
应用程序:didFinishLaunchingWithOptions:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
NSAssert([tabBarController isKindOfClass:[UITabBarController class]], @"self.window.rootViewController must be a tabBarController");
for (UIViewController *viewController in tabBarController.viewControllers) {
    UITabBarItem *tabBarItem = viewController.tabBarItem;
    UIImage *tabImage = tabBarItem.image;
    [tabBarItem setFinishedSelectedImage:tabImage withFinishedUnselectedImage:tabImage];
}

我通过故事板设置图像。因此,我没有每个tabBarItem的名称。您无法从故事板设置完成的图像,因此您必须向应用程序代理添加一些代码。请参见编辑。这是他们的一种使用方法吗<代码>initWithTitle:(NSString*)@“title”图像:(UIImage*)[UIImage ImageName:@“sample image”]选择图像:(UIImage*)[UIImage ImageName:@“sample image”]您的方法在ios 7中已被弃用
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
NSAssert([tabBarController isKindOfClass:[UITabBarController class]], @"self.window.rootViewController must be a tabBarController");
for (UIViewController *viewController in tabBarController.viewControllers) {
    UITabBarItem *tabBarItem = viewController.tabBarItem;
    UIImage *tabImage = tabBarItem.image;
    [tabBarItem setFinishedSelectedImage:tabImage withFinishedUnselectedImage:tabImage];
}