Ios 图像未正确显示在UIScrollView上
我在UIScrollView中有图像,但图像显示不正确。问题是图像的大小不同。我希望每个图像的大小和高度都相同Ios 图像未正确显示在UIScrollView上,ios,uiscrollview,uiimageview,Ios,Uiscrollview,Uiimageview,我在UIScrollView中有图像,但图像显示不正确。问题是图像的大小不同。我希望每个图像的大小和高度都相同 for (UIView *v in [_scrollView subviews]) { [v removeFromSuperview]; } //CGRect workingFrame = _scrollView.frame; CGRect workingFrame = CGRectMake(0, 0, 200, 134); workingFrame.origin.x =0;
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)];
如果设置
UIViewContentModeScaleAspectFit
,则图像的大小将达到UIImageView的最大值,但通常更小。如果您希望填充并具有相同的大小并保持纵横比,则必须设置:
[imageview setContentMode:UIViewContentModeScaleAspectFill];
[imageview setClipsToBounds:YES];