0

In my table cell I am having different controls like ImageView, Label, Buttons.

In that ImageView is for UserProfile Image. When the user clicks the ProfileImage it has to highlight.

For that I am using the following code

- (IBAction)UserImageClick:(id)sender{
    UITapGestureRecognizer *tapRecognizer = (UITapGestureRecognizer *)sender;
    NSString *strUserID,*strUsername, *strUserProfileImage;
    NSDictionary *dictionary = [self.allPostArray objectAtIndex:[tapRecognizer.view tag]];
    strUserID = [dictionary valueForKey:@"user_id"];
    strUsername= [dictionary valueForKey:@"username"];
    strUserProfileImage = [dictionary valueForKey:@"userprofileimage"];
    [sender setHighlighted:YES animated:YES];
}

Is there any way to highlight the sender and animate it? Here the sender is a ImageView.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Subramanian Raj
  • 389
  • 2
  • 5
  • 16

2 Answers2

0

You need to change the color of the border of UIImageView's layer. Being that UIImageView inherits from UIView, it has a .layer property, which is a CALayer. Something like this...

 UIImageView *imageView = (UIImageView *)sender;

 UIColor *borderColor = [UIColor greenColor];
 [imageView.layer setBorderColor:borderColor.CGColor];
 [imageView.layer setBorderWidth:3.0];

Link to the Apple docs for CALayer

bolnad
  • 4,533
  • 3
  • 29
  • 41
0

Try this code: it work for me

_image.userInteractionEnabled = YES;

_image.tag = 1;

_image.layer.opacity=0.80;

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

UITouch *touch = [[event allTouches] anyObject];

[super touchesBegan:touches withEvent:event];

if ([touch view] == [_image viewWithTag:1]) 

 {

  _image.backgroundColor=[UIColor blueColor];

  _image.layer.opacity=3;

 }

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event allTouches] anyObject];

[super touchesBegan:touches withEvent:event];

if ([touch view] == [_image viewWithTag:1]) 

 {     
  _image.backgroundColor=[UIColor blueColor];

  _image.layer.opacity=0.80;

}
parthiban
  • 95
  • 9