表格单元格中的ImageView突出显示

时间:2016-01-28 02:06:07

标签: ios objective-c uiimageview

在我的表格单元格中,我有不同的控件,如ImageView,Label,Buttons。

因为ImageView适用于UserProfile Image。当用户单击ProfileImage时,它必须突出显示。

为此,我使用以下代码

- (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];
}

有没有办法突出显示发件人并为其设置动画?这里的发件人是ImageView。

2 个答案:

答案 0 :(得分:0)

您需要更改UIImageView图层边框的颜色。由于UIImageView继承自UIView,它具有.layer属性,这是一个CALayer。像这样......

 UIImageView *imageView = (UIImageView *)sender;

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

指向CALayer

的Apple文档的链接

答案 1 :(得分:0)

试试这段代码: 它对我有用

_image.userInteractionEnabled = YES;

_image.tag = 1;

_image.layer.opacity = 0.80;

- (void)touchesBegan:(NSSet *)触及withEvent:(UIEvent *)事件

{

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 *)触及withEvent:(UIEvent *)事件  {

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;

}