【发布时间】:2014-06-02 00:41:16
【问题描述】:
我有一组以编程方式生成的图像。在每张图片上,我都添加了一个点击手势。我想要发生的是,当点击该图像时,边框变为黑色。
目前,我正在尝试将参数传递给将在数组列表中找到图像的方法。我正在努力寻找正确的语法来传递该参数
这里是代码。任何帮助表示赞赏!
- (void)viewDidLoad
{
[super viewDidLoad];
int recents = 10;
int x = 10;
_recent.contentSize = CGSizeMake((x*120)+10,100 );
for(int i = 0; i <=recents; i ++){
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, 10, 90, 90)];
[_arrayImages addObject:_imageView];
NSURL *url = [NSURL URLWithString:@"http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
_imageView.image = [[UIImage alloc] initWithData:data];
_imageView.layer.masksToBounds = YES;
_imageView.layer.cornerRadius = 45.0;
_imageView.layer.borderColor = [UIColor blueColor].CGColor;
_imageView.layer.borderWidth = 3.0f;
_imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;
_imageView.layer.shouldRasterize = YES;
NSUInteger * count;
_imageView.tag = i;
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(didTapImageWithGesture:)];
tapGesture.numberOfTapsRequired = 1;
[_imageView addGestureRecognizer:tapGesture];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, 110, 90, 24)];
label.text = @"Sam Stone";
label.font = [UIFont fontWithName:@"HelveticaNeue" size:12];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
label.textAlignment = NSTextAlignmentCenter;
[_recent addSubview:_imageView];
[_recent addSubview:label];
[_arrayImages addObject:_imageView];
x=x+110;
}
}
- (void)didTapImageWithGesture:(id)sender {
UIImageView *image;
image = [_arrayImages objectAtIndex:((UIGestureRecognizer *)sender).view.tag];
image.layer.borderColor = [UIColor blackColor].CGColor;
}
【问题讨论】:
标签: ios iphone objective-c uitapgesturerecognizer