Pages

Saturday, August 3, 2013

Add Image from URL in UIView and make clickable

I have made a sample code for this example

Step 1 - Load Image from URL

     UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"screen.png"]];

  [self.completeSingleView addSubview:imageView];

Step 2 - Now to make this clickable just use the following code

    imageView.userInteractionEnabled = YES;
   imageView.tag = 2;

Step 3 - Now to add this in any UIView. Follow the code below

     [self.completeSingleView addSubview:imageView];

Step 4- Now to detect the Image in touch began event, follow the code below


-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    
    UITouch *touch = [touches anyObject];
    if([touch.view tag] == 2)
        NSLog(@"Your Image is Touched");
}

No comments:

Post a Comment