0

我在 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)];
4

1 回答 1

0

如果您设置UIViewContentModeScaleAspectFit,您将拥有 UIImageView 的最大尺寸的图像,但通常更小。如果您希望它填充并具有所有相同的大小并保持纵横比,您必须设置:

[imageview setContentMode:UIViewContentModeScaleAspectFill];
[imageview setClipsToBounds:YES];
于 2013-07-26T18:51:23.867 回答