iPhone以编程方式实例化UITabBarItem

编程入门 行业动态 更新时间:2024-10-23 22:32:00
本文介绍了iPhone以编程方式实例化UITabBarItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尽我所能,我无法使它正常工作.这是我最近的尝试.有人可以告诉我为什么这行不通吗?

Try as I might, I cannot get this to work. Here is my latest attempt. Can someone clue me in as to why this does not work?

在我的视图控制器的init方法调用的方法中:

In a method which is called by my view controller's init method:

UIImage *image = [UIImage imageNamed: @"window22.png"]; UITabBarItem *item = [[UITabBarItem alloc] initWithTitle: @"Some Title" image: image tag: 0]; self.tabBarItem = item;

它所做的只是在应该放置图像的地方放一个大正方形.标签栏中的标题与视图控制器的标题相同.

All it does is put a big square where the image should be. The title in the tab bar remains the same as the view controller's title.

这里所有的内容都以编程方式实例化,包括标签栏控制器.

Everything is being instantiated programmatically here, including the tab bar controller.

推荐答案

根据文档,tabBarItem将自动实例化-您无需自己创建它.当我在tabBar中为视图控制器设置标题和图像时,我就使用了

According to the docs, the tabBarItem will be instantiated automatically- you don't need to create it yourself. When I've set the title and image in the tabBar for a view controller, I've used

self.tabBarItem.image = [UIImage imageNamed:imageName];

更多推荐

iPhone以编程方式实例化UITabBarItem

本文发布于:2023-11-24 08:56:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实例   方式   iPhone   UITabBarItem

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!