UITabBarController未选中的图标图像色调 [英] UITabBarController unselected icon image tint

查看:96
本文介绍了UITabBarController未选中的图标图像色调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我试图修改的UITabBarController。现在,未选中的选项卡图标图像是默认灰色。我知道您无法以编程方式更改这些未选择的图标图像的色调。 Apple说色调是由png文件本身的实际色调控制的。因此,如果你想要一个白色或绿色图标图像,那么你必须使用一个显示图像为白色或绿色等的png。之后你必须使用UIImageRenderingModeAlwaysOriginal和initWithTitle:image:selectedImage:我在我的FirstViewController.m中使用了这个代码我把它放在 - (void)viewDidLoad中。但是,我得到一个解析问题:期望的标识符及其指向nil之后的括号。有没有人看到这个代码的问题?

I have a UITabBarController that I am trying to modify. Right now the UNselected tab icon images are default gray. I know that you cant change the tint of these UNselected icon images programmatically. Apple says that the tint is controlled by the actual tint of the png file itself. So if you want a white or green icon image then you have to use a png that displays the image as white or green etc. After that you must use UIImageRenderingModeAlwaysOriginal AND initWithTitle:image:selectedImage: I used this code in my FirstViewController.m and i placed it in the -(void)viewDidLoad. However, I am getting a parse issue: expected identifier and its pointing at the bracket after nil. Does anybody see the issue with this code?

//
//  FirstViewController.m
//  tabmock5
//
//  Created by USER on 9/26/13.
//  Copyright (c) 2013 USER. All rights reserved.
//

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad
{
[[UIImage imageNamed:@"white_stats.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

[self.tabBarItem initWithTitle:[nil]image:[UIImage imageNamed:@"white_stats.png"]selectedImage:[UIImage imageNamed:@"white_stats.png"]];

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}


推荐答案

[[UIImage imageNamed:@"white_stats.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

这不是将图像保存在任何地方。将其更改为:

This isn't saving the image anywhere. Change it to:

UIImage *myImage = [[UIImage imageNamed:@"white_stats.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

这个:

[self.tabBarItem initWithTitle:[nil]image:[UIImage imageNamed:@"white_stats.png"]selectedImage:[UIImage imageNamed:@"white_stats.png"]];

nil 不是对象(它没有放在方括号内)。将其更改为:

nil isn't an object (it doesn't go in square brackets). Change this to:

[self.tabBarItem initWithTitle:nil image:myImage selectedImage:[UIImage imageNamed:@"white_stats.png"]];

或者,您可以在一行中完成此操作:

Alternatively, you can technically do this in one line:

[self.tabBarItem initWithTitle:nil image:[[UIImage imageNamed:@"white_stats.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[UIImage imageNamed:@"white_stats.png"]];

但是如果你以后需要再回来它很难读,所以不要这样做那个。

But that is hard to read if you need to come back to it later, so don't do that.

这篇关于UITabBarController未选中的图标图像色调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆