2013-07-26 48 views
0

我在UIScrollView中显示图像,但图像显示不正确。问题是图像尺寸不一样。我希望每个图像具有相同的大小和高度。图像在UIScrollView上显示不正确

for (UIView *v in [_scrollView subviews]) { 
    [v removeFromSuperview]; 
} 

//CGRect workingFrame = _scrollView.frame; 
CGRect workingFrame = CGRectMake(0, 0, 200, 134); 
workingFrame.origin.x =0; 

NSMutableArray *images = [NSMutableArray arrayWithCapacity:[info count]]; 


for(NSDictionary *dict in info) { 

    UIImage *image = [dict objectForKey:UIImagePickerControllerOriginalImage]; 
    [images addObject:image]; 

    UIImageView *imageview = [[UIImageView alloc] initWithImage:image]; 
    [imageview setContentMode:UIViewContentModeScaleAspectFit]; 
    imageview.frame = workingFrame; 

    [_scrollView addSubview:imageview]; 
    [imageview release]; 

    workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width; 
} 

self.chosenImages = images; 
NSLog(@"values=%@",_chosenImages); 

[_scrollView setPagingEnabled:YES]; 
[_scrollView setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)]; 

回答

0

如果设置UIViewContentModeScaleAspectFit你将不得不与的UIImageView的最大尺寸,但往往更小的图像。如果您想要它填充并具有完全相同的尺寸并保持不变,您必须设置:

[imageview setContentMode:UIViewContentModeScaleAspectFill]; 
[imageview setClipsToBounds:YES];