从滚动视图中添加多个图像
问题描述:
我需要从滚动视图中选择多个图像。从滚动视图中添加多个图像
如果我触摸该图像,它会显示一个选择打勾(检查)标记;如果我再次触摸它,那么它将被取消选择。
我现在做这样的:
我想它,这样,当我说具体的图像上点击它会显示一个勾号(检查)标志;如果我触摸第二张照片,那么它会显示该图像的一个勾号(检查),与我们从相机胶卷中选择图像一样。
所以,请尽快帮助我。
下面是我的代码:
-(void)listimagesandanmae
{
int myFavV = [favCompcamelIDArr count];
for (int i = 0; i < myFavV; i++)
{
CGFloat xOrigin = i * 100;
favimageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin+20,10,70,70)];
favimageView.layer.cornerRadius = favimageView.frame.size.width/2;
favimageView.clipsToBounds = YES;
// imageView.layer.cornerRadius = 60;
// imageView.clipsToBounds = YES;
favimageView.tag=i;
NSInteger tag = favimageView.tag;
// then do what you want with this
if (([favCompcamelIDArr count] >0)) {
}
favnamelistingLbl=[[UILabel alloc]initWithFrame:CGRectMake(xOrigin+23,90,90,27)];
favnamelistingLbl.textAlignment = NSTextAlignmentCenter;
favnamelistingLbl.tag=i;
NSLog(@"%lu",(unsigned long)[favcompnsmeArr count]);
if (([favCompcamelIDArr count] > 0)) {
favnamelistingLbl.text=[favcompnsmeArr objectAtIndex:i];
}
[_selectCamelFav addSubview:favnamelistingLbl];
UITapGestureRecognizer *tappedmyFav = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedmyFav:)];
tappedmyFav.numberOfTapsRequired = 1;
[favimageView addGestureRecognizer:tappedmyFav];
NSLog(@"%ld",(long)tag);
NSString *[email protected]"http://192.8.1.42:/da/";
NSString *urStCam1=[urStCam stringByAppendingString:[favcompictureArr objectAtIndex:i]];
NSString *urStCam2= [urStCam1 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
[caArray addObject:urStCam2];
NSLog(@"%@",caArray);
NSURL *newUrl=[NSURL URLWithString:[caArray objectAtIndex:i]];
NSData *imageDatash = [NSData dataWithContentsOfURL:newUrl];
UIImage *image123 = [UIImage imageWithData:imageDatash scale:2.0];
[favimageView setImage:image123];
[_selectCamelFav addSubview:favimageView];
favimageView.userInteractionEnabled = YES;
}
_selectCamelFav.contentSize = CGSizeMake(myFavV * 210, 171);
[_indicatorA startAnimating];
_indicatorA.hidden=YES;
}
- (void)tappedmyFav:(UITapGestureRecognizer*)tap
{
UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) tap;
}
答
你应该继承的UIView。然后添加UIImageView,UILabel(复选标记)和一个属性来控制是否选择了UIView。同时添加点击手势处理程序(点击时选择=!)
要搜索选择哪个视图,请搜索滚动视图以查找'selected'UIView对象。或者你可以维护自己的列表,一旦对象被选中/取消选中,这样你就不需要搜索所有的对象。
为什么不使用'UICollectionView'或'UITableView'。它会容易得多。 – Ryan 2015-03-20 00:29:59