Iphone UITabBarItem 图像未显示

发布于 2025-01-05 15:10:56 字数 330 浏览 2 评论 0原文

我的问题是如何添加 UITabBarController 的 childViewController 的图标。我的代码是:

UITabBarController *tabBar=[[UITabBarController alloc]init];
MyUIViewController *mc=[[MyUIViewController alloc]init];
[tabBar addChildViewController:mc];
[self.navigationController pushViewController:tabBar animated:YES];

提前致谢。

My question is how I could add the icon of a childViewController of an UITabBarController. My code is:

UITabBarController *tabBar=[[UITabBarController alloc]init];
MyUIViewController *mc=[[MyUIViewController alloc]init];
[tabBar addChildViewController:mc];
[self.navigationController pushViewController:tabBar animated:YES];

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

jJeQQOZ5 2025-01-12 15:10:56

请尝试这个

UITabBarController *tabController = [[UITabBarController alloc] init];
SomeViewController *viewController = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil];
[tabController setViewControllers:[NSArray arrayWithObject:viewController]];//Setting child viewController Array.
UITabBarItem *item = (UITabBarItem *)[tabController.tabBar.items objectAtIndex:0]; //for first view
[item setImage:[UIImage imageNamed:@"someImage.png"]]; //Image should be 23px X 23px ,I think so.

Please try this

UITabBarController *tabController = [[UITabBarController alloc] init];
SomeViewController *viewController = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil];
[tabController setViewControllers:[NSArray arrayWithObject:viewController]];//Setting child viewController Array.
UITabBarItem *item = (UITabBarItem *)[tabController.tabBar.items objectAtIndex:0]; //for first view
[item setImage:[UIImage imageNamed:@"someImage.png"]]; //Image should be 23px X 23px ,I think so.
双手揣兜 2025-01-12 15:10:56

我通过在 MyUIViewController: 中添加属性和属性解决了这个问题:

@interface MyUIViewController{
    UITabBarItem *tabBarItem;
}
@property (nonatomic, retain) UITabBarItem *tabBarItem;

然后用图像初始化它:

UITabBarController *tabBar=[[UITabBarController alloc]init];
MyUIViewController *mc=[[MyUIViewController alloc]init];
mc.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"MyTitle" image:[UIImage imageNamed:@"myImage.png"] tag:0];
[tabBar addChildViewController:mc];
[self.navigationController pushViewController:tabBar animated:YES];

I have solved this by adding an attribute and property in MyUIViewController:

@interface MyUIViewController{
    UITabBarItem *tabBarItem;
}
@property (nonatomic, retain) UITabBarItem *tabBarItem;

and then initialize it with an image:

UITabBarController *tabBar=[[UITabBarController alloc]init];
MyUIViewController *mc=[[MyUIViewController alloc]init];
mc.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"MyTitle" image:[UIImage imageNamed:@"myImage.png"] tag:0];
[tabBar addChildViewController:mc];
[self.navigationController pushViewController:tabBar animated:YES];
迎风吟唱 2025-01-12 15:10:56

我刚刚发现桌面不区分大小写,但是设备要求代码具有相同的字母数字大小写(大写/小写)。确保文件名相同......具体到大小写(大写/小写)!

示例:

“first.png”在磁盘上的文件名最好表示为 -->
self.tabBarItem.image = [UIImage imageNamed:@"first"];

不是 -- 不是 --- 不是

self.tabBarItem.image = [UIImage imageNamed:@"First"];

今天大写的“F”踢了我三个小时!由于这个疏忽,我今天损失了 3 个小时的生命。希望这对其他人有帮助。

I just discovered that the desktop is case insensitive, however the device requires the code to have the same alpha-numberic case (upper/lower). Make sure the name of the file is the same ... down to the case (upper/lower)!

Example:

The file name on disk of "first.png" had better be represented as -->
self.tabBarItem.image = [UIImage imageNamed:@"first"];

NOT -- NOT --- NOT

self.tabBarItem.image = [UIImage imageNamed:@"First"];

The capital 'F' kicked my arse for 3 hours today! I lost 3 hours of my life today because of this oversight. Hope this helps someone else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文