我在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 :(得分:0)
如果设置UIViewContentModeScaleAspectFit
,您将获得具有UIImageView最大大小的图像,但通常更小。如果您希望它填充并具有所有相同的大小并保持您必须设置的方面:
[imageview setContentMode:UIViewContentModeScaleAspectFill];
[imageview setClipsToBounds:YES];