Iphone 关于UIBarbuttonite的图像
在我的iPhone应用程序中,我在UINavigation控制器上添加了一个工具栏,因为导航栏上的按钮不超过两个。 目前为止我已经成功地添加了带有三个按钮的UIToolBar。但是,我无法在BarButtonItems上显示图像Iphone 关于UIBarbuttonite的图像,iphone,ios4,Iphone,Ios4,在我的iPhone应用程序中,我在UINavigation控制器上添加了一个工具栏,因为导航栏上的按钮不超过两个。 目前为止我已经成功地添加了带有三个按钮的UIToolBar。但是,我无法在BarButtonItems上显示图像 谁能告诉我。。如何在UIToolBar BarButtonims上添加图像?其中,导航控制器上已添加工具栏 为uibarbuttonite设置一个自定义视图,如下所示 UIBarButtonItem *barButton = [[UIBarButtonItem
谁能告诉我。。如何在UIToolBar BarButtonims上添加图像?其中,导航控制器上已添加工具栏 为uibarbuttonite设置一个自定义视图,如下所示
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *yourImage = [UIImage imageNamed:@"yourImage.png"];
[button setImage:yourImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(yourButtonAction) forControlEvents:UIControlEventTouchUpInside];
[barButton setCustomView:button];
self.navigationItem.rightBarButtonItem = barButton;
[barButton release];
试试这个。谢谢!我测试了这段代码,当我创建一个新的应用程序时,它运行良好。但无论如何,它在我的项目中不起作用。而且它没有显示任何错误。。请建议!您是否使用了导航控制器基本视图或当前模式视图导航控制器,我正在将其隐藏到viewWillApper中。。[self.navigationController设置NavigationBarHidden:是动画:是];GhostRider,你知道我哪里弄错了吗?我在ViewWillAspect方法中添加了这段代码..我将导航栏隐藏在那里。这是一个不显示图像的问题吗??
button = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:image]];
button.action = @selector(myaction);
button.target = self;