Question

who can help me with this code? Simply it doesn't work, same as ALL I have tried for vertical scrolling. I'm starting to think that my Xcode emulator has something wrong. Here's the code:

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 30, 300, 400)];
[self.view addSubview:scroll];
[scroll setBackgroundColor:[UIColor redColor]];
{

    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1222, 400)];
    [imageview setImage:[UIImage imageNamed:@"panorama_orizzonte_medio_big.jpg"]];
    [scroll addSubview:imageview];
    [self.view addSubview:scroll];
}
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
Was it helpful?

Solution

After you set the UIImageView, you need to set the scrollView's contentSize to that of your imageView's, so, something like this:

[scroll setContentSize:imageview.frame.size];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top