iOS 5:UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage:not working / ignored [英] iOS 5: UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage: not working / ignored

查看:86
本文介绍了iOS 5:UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage:not working / ignored的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Apple docs

我正在尝试在UITabBarItem上设置自定义完成的已选择和未选择的图像,如下所示:

I'm trying to set custom finished selected and unselected images on a UITabBarItem like so:


...
DetailViewController *vc1 = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
UITabBarItem *vc1i = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:100];
[vc1i setFinishedSelectedImage:[UIImage imageNamed:@"tab_bar_item_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_bar_item_normal.png"]];
[vc1 setTabBarItem:vc1i];
...

基本上发生的事情是TabBar加载很好,它只是完全忽略标签栏项目自定义。

Basically what's happening is the TabBar loads up just fine, it just completely ignores the tab bar item customization.

我的目标是iOS5 +

I'm targeting iOS5+

图像是30x30透明PNG并且存在在项目中。无法弄清楚我在这里忽略了什么,但必定是什么!

The images are 30x30 transparent PNGs and exist in the project. Can't figure out what I'm overlooking here, but must be something!

这是在 tableView中调用的:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 方法,ala Ray Wenderlich的教程

This is being called in the tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method, ala Ray Wenderlich's tutorial

任何人都有任何想法?

谢谢!

推荐答案

使用以下方法初始化标签栏项: initWithTabBarSystemItem:tag:。但是,正如文档所说:

The tab bar item is initialized with the method: initWithTabBarSystemItem:tag:. But, as the documentation says:


此方法返回系统提供的标签栏项。以后不能更改返回项目的标题和图像属性。

This method returns a system-supplied tab bar item. The title and image properties of the returned item cannot be changed later.

您应该使用 initWithTitle:image:tag:。

UITabBarItem *vc1i = [[UITabBarItem alloc] initWithTitle:@"Top Rated" image:nil tag:100];
[vc1i setFinishedSelectedImage:[UIImage imageNamed:@"tab_bar_item_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_bar_item_normal.png"]];

这篇关于iOS 5:UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage:not working / ignored的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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