我有一个 JSON 服务,我在其中使用一些照片。我想从中制作一个缩略图库:
-(void)fillPhotos:(NSMutableArray *)json{
_loadingLabel.alpha=0;
[SV setScrollEnabled:YES];
if(json.count>0){
NSDictionary *json_dictionary=[json objectAtIndex:0];
NSInteger i=0;
for(i=0;i<[[json_dictionary objectForKey:@"Photos"] count];i++){
NSDictionary *photosDic =[[json_dictionary objectForKey:@"Photos"] objectAtIndex:i] ;
NSString *imageUrl = [photosDic objectForKey:@"URI"];
UIImageView* photo;
CGRect viewRect;
if(i % 2){
viewRect = CGRectMake(164,146*(i/2)+10*(i/2), 146, 146);
NSLog(@"par");
}else{
viewRect = CGRectMake(10,146*(i/2)+10*(i/2), 146, 146);
NSLog(@"impar");
}
photo = [[UIImageView alloc] initWithFrame:viewRect];
photo.image=[UIImage imageWithData: [NSData dataWithContentsOfURL:[NSURL URLWithString: imageUrl]]];
[SV addSubview:photo];
SV.contentSize=CGSizeMake(320,146*i+146);
[SV reloadInputViews];
}
}
}
它工作正常,但我有两个问题。首先,我希望视图逐张加载照片,因此用户不必等待 cicle 结束即可一次查看所有照片。其次,我希望照片在中心裁剪,但只占用 146x146 帧。但是,如果我将 Top 置于 contentmode 中,照片就会从他的框架中拉出。
你能帮我解决这个问题吗?