【发布时间】:2016-02-26 07:44:53
【问题描述】:
实际上我想将图像和标签作为 UIBarButtonItem 放置在工具栏上,并为该按钮提供可点击的效果。
所以我在这里所做的是我创建了一个自定义视图并将 Image 和 Label 放在同一个自定义视图上,最后将此自定义视图放置为 UIBarButtonItem CustomView。
但是当我为同一个 UIBarButtonItem 设置目标和动作时,它并没有调用选择器方法。
整个代码如下。
谁能建议我的代码有什么错误?还有其他方法可以达到同样的效果吗????
非常感谢早期的建议。
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setToolbarHidden:NO];
UIView *customView = [[UIView alloc]
initWithFrame:CGRectMake(0,0,self.navigationController.toolbar.frame.size.width,self.navigationController.toolbar.frame.size.height)];
customView.backgroundColor = [UIColor colorWithRed:62.0/255.0 green:187.0/255.0 blue:150.0/255.0 alpha:1.0];
[self.navigationController.toolbar addSubview:customView];
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(60,0,44,44)];
imgView.image = [UIImage imageNamed:@"documentImage.png"];
[customView addSubview:imgView];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(104,0,145,44)];
lbl.text = @"Scan Document";
lbl.textAlignment = NSTextAlignmentLeft;
[customView addSubview:lbl];
UIBarButtonItem *bar = [[UIBarButtonItem alloc]initWithCustomView:customView];
bar.target = self;
bar.action = @selector(scanDocument);
self.toolbarItems = [NSArray arrayWithObjects:bar, nil];
}
【问题讨论】:
-
您的 scanDocument 定义为接受参数还是不接受参数?
-(void) scanDocument:(UIBarButtonItem*)sender或-(void)scanDocument -
无参数只是-(void) ScanDocument
标签: ios objective-c iphone