我想将带有图像的条形按钮项更改为另一个条形按钮,其中包含不同的图像并执行不同的功能。有什么帮助吗?
问问题
3609 次
3 回答
3
在你的代码块中使用这样的:
UIImage *buttonImage = [UIImage imageNamed:@"customImage.png"];// set your image Name
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:buttonImage forState:UIControlStateNormal];
btn.frame = CGRectMake(0, 0, bImage.size.width, bImage.size.height);
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.barButtonItem = barButton;
于 2013-08-14T10:19:37.013 回答
1
试试这个代码,它是导航栏中图像栏按钮的自定义视图
UIImage* image3 = [UIImage imageNamed:@"mail-48_24.png"];
CGRect frameimg = CGRectMake(0, 0, image3.size.width, image3.size.height);
UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
[someButton setBackgroundImage:image3 forState:UIControlStateNormal];
[someButton addTarget:self action:@selector(sendmail)
forControlEvents:UIControlEventTouchUpInside];
[someButton setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
self.navigationItem.rightBarButtonItem=mailbutton;
[someButton release];
于 2013-08-14T10:18:11.100 回答
0
设置原始图像并按下按钮转到目标方法设置另一个图像并根据barbutton文本重复此操作..
于 2013-08-14T10:15:43.660 回答