首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用故事板通过自定义图像设置iphone选项卡栏图标

如何使用故事板通过自定义图像设置iphone选项卡栏图标
EN

Stack Overflow用户
提问于 2012-12-21 18:13:39
回答 4查看 31.2K关注 0票数 15

我是新手到iphone的开发,我需要把一个自定义的图像图标在标签栏.But它只显示默认的颜色(黑色和蓝色) .Help我来克服这个bug朋友…?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-12-21 21:40:01

在应用程序中添加图像,

并查看附加的图像

票数 23
EN

Stack Overflow用户

发布于 2012-12-21 18:17:26

在viewDidLoad中使用此代码

代码语言:javascript
复制
UIImage *selectedImage0 = [UIImage imageNamed:@"selected.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"unselected.png"];

UITabBarItem *item0 = [tabBar.items objectAtIndex:0];

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
票数 6
EN

Stack Overflow用户

发布于 2014-06-16 01:04:43

您可以将以下代码片段用于ios7:

代码语言:javascript
复制
UIImage *iconBoxOffice = [UIImage imageNamed:@"box-office.png"];
UIImage *selectedIconBoxOffice = [UIImage imageNamed:@"selected-box-office.png"];
UIImage *iconDvds = [UIImage imageNamed:@"dvds.png"];
UIImage *selectedIconDvds = [UIImage imageNamed:@"dvds.png"];

UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];

[item0 initWithTitle:@"Box Office" image:iconBoxOffice selectedImage:selectedIconBoxOffice];
[item1 initWithTitle:@"Dvds" image:iconDvds selectedImage:selectedIconDvds];

如果你有更多的标签,你可以继续添加更多的项目。*不要忘记将图像添加到您的项目中*这是以编程方式完成的,而不是使用故事板

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13988162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档