iPhone instantiating a UITabBarItem programmatically

徘徊边缘 提交于 2019-12-12 18:17:33

问题


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?

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.


回答1:


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];


来源:https://stackoverflow.com/questions/2683907/iphone-instantiating-a-uitabbaritem-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!