如何在uitableViewcell中保留的imageview框架中放置一个信息按钮?
提前致谢!
答案 0 :(得分:4)
您需要做的就是创建按钮并将其添加到单元格中:
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton setFrame:CGRectMake(10,10,infoButton.frame.size.width, infoButton.frame.size.height)];
[infoButton addTarget:self action:@selector(infoButtonTapped) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:infoButton];
编辑---
如果您想使用单元格的imageView属性,则需要提供自己的图像,并且需要设置手势识别器,以便了解何时触发了imageView。
[cell.imageView setImage:[UIImage imageNamed:@"info-button.png"]];
[cell.imageView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(infoImageTapped:)];
[tap setNumberOfTapsRequired:1];
[cell.imageView setGestureRecognizers:[NSArray arrayWithObject:tap]];
[tap release];
- (void) infoImageTapped:(UITapGestureRecognizer *) tap {
//show info view.
}