iOS Developer iOS Developer - 1 year ago 90
Objective-C Question

show an image as enlarged on clicking an image view in iPhone

I have implemented async image view to load images on my custom cell views, but the images are showing as small on cells. So I need to show an enlarged form of that image when clicking on that image views. How can I achieve this?

This is my code:

if (cell == nil) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

//create new cell
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

//common settings
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.layer.cornerRadius = 10;
cell.layer.masksToBounds = YES;

cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
cell.imageView.frame = CGRectMake(10.0f, 10.0f, 60.0f, 44.0f);
cell.imageView.backgroundColor = [UIColor colorWithRed:73 green:73 blue:73 alpha:1];

cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
imgBtn=[cell imageView];
cell.imageView.imageURL = [NSURL URLWithString:[[detailsList objectAtIndex:indexPath.row]objectForKey:@"image_url"]];

I want to enlarge the image upon touching the image view inside the cell. Any ideas? Thanks in advance.

Answer Source

Try using a UIButton:

UIButton * b = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f , cell.imageView.frame.size.width, cell.imageView.frame.size.height)];
b.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[b addTarget:self action:@selector(changeSize:) forControlEvents:UIControlEventTouchUpInside];
[cell.imageView addSubview:b];

-(IBAction)changeSize:(UIButton *)sender
    UIImageView * imageView = (UIImageView *)[sender superview];
    imageView.frame = //Your larger frame goes here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download