0

I have a tableview cell with a custom image in the imageview of the cell. However, sometimes if you tap on the image (a checkbox), it taps on the actual cell instead of the image. I want to make it so if you tap part of the cell around the image, the checkbox is checked instead of the actual cell. How would I do this?

This is some code..

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cell.imageView.image = [UIImage imageNamed:@"unchecked.png"];

The image is a 28x28 image.

EvilAegis
  • 733
  • 1
  • 9
  • 18

2 Answers2

0

Probably the easiest way would be to create UITapGestureRecognizer and add it to cell.contentView using the same selector you are using for image tapping.

demosten
  • 3,301
  • 2
  • 25
  • 18
  • but how would i only get part of the content view? – EvilAegis Jul 07 '13 at 19:53
  • lets say like a 60x40 rectangle? – EvilAegis Jul 07 '13 at 19:55
  • you can subclass `UITableViewCell` and either set a bigger imageView size or leave it be, but add another `UIView` with the bigger size below it. Then add the gesture recognizer to it. Another option would be to use `UIControl` instead of `UIView` and just handle on touch up inside event (no gesture recognizer) – demosten Jul 07 '13 at 19:57
0

One simple way to solve this is to increase the width of the cell's image view.

Matt
  • 2,391
  • 2
  • 17
  • 18
  • how exactly do you access that property? it seems to be a read only – EvilAegis Jul 08 '13 at 01:42
  • wait would i just use cell.imageview.frame? – EvilAegis Jul 08 '13 at 01:44
  • You should subclass the cell and override the layoutSubviews method. Inside the method, set imageView.frame to whatever value you wish. – Matt Jul 08 '13 at 01:46
  • Also, if you're using the Sensible TableView framework, you can just use cell actions instead of subclassing the cell. – Matt Jul 08 '13 at 01:47
  • are you sure you changed the frame in layoutSubviews? – Matt Jul 08 '13 at 01:48
  • ok well i changed the layoutsubview and made the frame of the imageview CGRectMake(0,0,60,40), but it seems like the image gets resized...how could i just make the area of tapping increase but not the image? – EvilAegis Jul 08 '13 at 01:53
  • Check this: http://stackoverflow.com/questions/9255618/aspect-ratio-in-uiimageview – Matt Jul 08 '13 at 02:00