带有大图像的UIScrollView

时间:2013-03-15 01:15:22

标签: iphone uiview uiscrollview uiimageview

此代码显示scrollView,但我想要显示的图像(教程)比视图大。换句话说,tutorial.png正好是280X1200,但它不是aspectFit。我在这里错过了一些小事:

tipScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(20, 10, 280, 1200)];
tipScroll.showsVerticalScrollIndicator = YES;
tipScroll.scrollEnabled = YES;
tipScroll.userInteractionEnabled = YES;

UIImageView *tutorialImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tutorial"]];

tipScroll.contentMode = UIViewContentModeScaleAspectFit;
tutorialImageView.contentMode = UIViewContentModeScaleAspectFit;

tipScroll.contentSize = tutorialImageView.frame.size;

[self.view addSubview:tipScroll];
[tipScroll addSubview:tutorialImageView];

1 个答案:

答案 0 :(得分:2)

请查看以下编辑的代码。它将起作用

tipScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(20, 10, 280, 1200)];
tipScroll.showsVerticalScrollIndicator = YES;
tipScroll.scrollEnabled = YES;
tipScroll.userInteractionEnabled = YES;

UIImageView *tutorialImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 280, 1200)];
tutorialImageView.image = [UIImage imageNamed:@"tutorial"];

tipScroll.contentSize = tutorialImageView.frame.size;
[tipScroll addSubview:tutorialImageView];
[self.view addSubview:tipScroll];