- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.translucent = YES;
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"sprites_0001_Rectangle-1.png"] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.translucent = YES;
UIImageView *imageView = [[UIImageView alloc]init];
UIImage *image = [UIImage imageNamed:@"sprites_0000s_0008_1st-Page.png"];
imageView.image = image;
//imageView.translatesAutoresizingMaskIntoConstraints = NO;
imageView.backgroundColor = [UIColor clearColor];
self.view = imageView;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
//Write the code to set up view for iPad
}else{
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.backgroundColor = [UIColor clearColor];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:scrollView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-40-[scrollView(==240)]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(scrollView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[scrollView(==468)]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(scrollView)]];
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ParentsMock.png"]];
imageView.translatesAutoresizingMaskIntoConstraints = NO;
[scrollView addSubview:imageView];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[imageView(==1000)]|"
options:0
metrics:0
views:NSDictionaryOfVariableBindings(imageView)]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView(==2000)]|"
options:0
metrics:0
views:NSDictionaryOfVariableBindings(imageView)]];
}
This is my attempt to create UIScrollView
programmatically however I couldn't make the scrollView
work even though I set the contentSize
after adding the subview into the scrollView
.
As you can see in this picture, I use UINavigationController to wrap a UIViewControllar and set UIImageView as its view. the I created a scrollView and add it on top of the view. then I create another imageView1 and insert it into the scrollView.
please note that the view of the entire view controller is an imageView which is different from the imageView i insert into the scrollView.