0
我需要從滾動視圖中選擇多個圖像。從滾動視圖中添加多個圖像
如果我觸摸該圖像,它會顯示一個選擇打勾(檢查)標記;如果我再次觸摸它,那麼它將被取消選擇。
我現在做這樣的:
我想它,這樣,當我說具體的圖像上點擊它會顯示一個勾號(檢查)標誌;如果我觸摸第二張照片,那麼它會顯示該圖像的一個勾號(檢查),與我們從相機膠捲中選擇圖像一樣。
所以,請儘快幫助我。
下面是我的代碼:
-(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;
}
爲什麼不使用'UICollectionView'或'UITableView'。它會容易得多。 – Ryan 2015-03-20 00:29:59