UIImageView在UIScrollView?
问题描述:
我想在UIScrollView
中有UIImageView
。但是,我加载它时没有显示任何图片。我的代码看起来像这样在我viewController
在功能viewDidLoad
:UIImageView在UIScrollView?
UIImage *image = [UIImage imageNamed:@"plan.gif"];
imageView = [[UIImageView alloc] initWithImage:image];
scrollView = [[UIScrollView alloc] init];
[scrollView addSubview:imageView];
scrollView.contentSize = image.size;
[self updateUI];
在我didFinishLaunchingWithOptions:
TestAppViewController *tavc = [[TestAppViewController alloc] init];
[self.window addSubview:tavc.view];
答
1)检查您的图像名称@"plan.gif"
是正确的。再检查一遍。
2)用一个帧初始化你的UIImageView
并稍后添加图像。
imageView = [[UIImageView alloc] initWithFrame:
CGRectMake(0,0,scrollView.frame.size.width, scrollView.frame.size.height)];
// or choose another size
imageView.image = [UIImage imageNamed:@"plan.gif"];
+0
我刚试过,不起作用。我认为这是因为我的scrollView没有显示出来。 我在做我的scrollView可能吗?也许我不应该在我的ViewController中做到这一点? – WYS
你添加了:[self.view addSubview:scrollView]; ?或者它缺少? – AmineG