我正在研究一个应用程序,并且想要自定义UItabbar图标图像。如何更改UItabbar图标图像?
我有一个名字about.png的图像我想设置为我应用程序的UItabbar的左侧图标图像。 我该怎么做?
我正在研究一个应用程序,并且想要自定义UItabbar图标图像。如何更改UItabbar图标图像?
我有一个名字about.png的图像我想设置为我应用程序的UItabbar的左侧图标图像。 我该怎么做?
K优使用此代码,并使用自己的图像,而不是建立在一个人的使用您的图片...
- (id)init {
UIImage* anImage = [UIImage imageNamed:@"newspaper.png"];
UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"News" image:anImage tag:0];
self.tabBarItem = theItem;
[theItem release];
return self; }
newspaper.png是我的在标签栏自己的图片...
K精现在这将足以满足您的问题...
如果你想改变形象的UITabbarItem你可以利用它的实例方法的
- (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag
中的viewController中,你正在使用标签实现的init()。
- (id)init {
if (self = [super initWithNibName:@"Search" bundle:nil]) {
UIImage* tabImage = [UIImage imageNamed:@"search.png"];
UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"Search" image:tabImage tag:0];
self.tabBarItem = theItem;
[theItem release];
}
return self;
}
总有一些通过编程方式这样做的,或通过使用直观两种方式(使用IB)
编程: -
UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"News" image:anImage tag:0];
使用这个,或者如果你正在做视觉: - 点击IB中特定的标签图标,选择自定义和图标,并给出特定图标文件的名称。
可能,这将解决您的问题...
我没有想使用内置的我不是说你使用内置在图像的Xcode – 2011-05-25 11:01:56
的图像Xcode只是看看我的新答案发布在我的列表中... – user755278 2011-05-25 11:19:03
你可以改变它喜欢。 中的TabBar控制器的委托方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if([tabBarController selectedIndex] == 0)
{
[viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
}
}
通过这个,你可以改变你的形象tabbaritem。
或者你可以在你的视图控制器的init(或viewWillAppear中)的方法直接使用,如
[viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
我可以在委托实现文件中使用此代码吗? 它会产生一个关于tabBarItem的错误 – 2011-05-25 11:27:59