从滚动视图添加多个图像
Adding multiple images from a scrollview
我需要 select 滚动视图中的多张图片。
如果我触摸该图像,它会显示 selection 刻度(复选)标记;如果我再碰它,它就会被 deselected。
现在我是这样做的:
我希望当我点击那个特定的图像时它会显示一个勾号(复选标记);如果我触摸第二个,那么它会为这张图片显示一个勾号(打勾),就像我们从相机胶卷中 select 图片一样。
所以,请尽快帮助我。
以下是我的代码:
-(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 *urStCam=@"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 是否被选中。同时添加 Tap 手势处理程序(选择 = !selected when tapped)
要搜索选择了哪个视图,请在滚动视图中搜索 'selected' UIView 对象。或者您可以在对象为 'selected/unselected' 时维护自己的列表,这样您就不需要搜索所有对象。
我需要 select 滚动视图中的多张图片。
如果我触摸该图像,它会显示 selection 刻度(复选)标记;如果我再碰它,它就会被 deselected。
现在我是这样做的:
我希望当我点击那个特定的图像时它会显示一个勾号(复选标记);如果我触摸第二个,那么它会为这张图片显示一个勾号(打勾),就像我们从相机胶卷中 select 图片一样。
所以,请尽快帮助我。
以下是我的代码:
-(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 *urStCam=@"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 是否被选中。同时添加 Tap 手势处理程序(选择 = !selected when tapped)
要搜索选择了哪个视图,请在滚动视图中搜索 'selected' UIView 对象。或者您可以在对象为 'selected/unselected' 时维护自己的列表,这样您就不需要搜索所有对象。