开发者

UIImageView in UIScrollView?

开发者 https://www.devze.com 2023-04-11 21:12 出处:网络
I want to have an UIImageView in an UIScrollView. But I it doesn\'t show any picture when I load it. My code looks like this in my viewController in the function viewDidLoad:

I want to have an UIImageView in an UIScrollView. But I it doesn't show any picture when I load it. My code looks like this in my viewController in the function viewDidLoad:

UIImage *image = [UIImage imageNamed:@"plan.gif"];
imageView = [[UI开发者_运维技巧ImageView alloc] initWithImage:image];
scrollView = [[UIScrollView alloc] init];
[scrollView addSubview:imageView];
scrollView.contentSize = image.size;
[self updateUI];

In my didFinishLaunchingWithOptions:

TestAppViewController *tavc = [[TestAppViewController alloc] init];
[self.window addSubview:tavc.view];


1) Check that your image name @"plan.gif" is correct. Double-check.
2) Init your UIImageView with a frame and add the image later.

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"];


Make sure that you have added the image to the project. Also, make sure that the file name is exactly the same (cAsE sensitive & correct extension).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号