0

This is the code of the page I am trying to implement . Its a settings page for a game im working on. I have created an outerView (called outerView) which contains the scrollView and the scrollView itself contains a UIView which has all the main content like buttons and labels . I am having troubles getting this scrollView to scroll up and down the screen. Any help will be appreciated

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView; 
@property (weak, nonatomic) IBOutlet UIView *containerView;
    @property (weak, nonatomic) IBOutlet UIView *outerView;

    @end

    @implementation SettingsViewController

    #define music_key music
    #define sound_key sound


    -(void)viewDidLoad
    {
        [super viewDidLoad];
        [self checkValues];
        [self makeSettingsPage];
    }
    -(void)makeSettingsPage
    {
        [self.scrollView setContentMode:UIViewContentModeScaleAspectFit];

        //Content Size is size of the view inside the scrollview
        self.scrollView.contentSize = CGSizeMake(_outerView.frame.size.width,_outerView.frame.size.height);


        RoundButton *about=[[RoundButton alloc]initWithColor:color1 WithText:@"ABOUT"];
        RoundButton *privacyPolicy=[[RoundButton alloc]initWithColor:color2 WithText:@"PRIVACY \n POLICY"];
        RoundButton *termsOfUse=[[RoundButton alloc]initWithColor:color2 WithText:@"TERMS \n OF USE"];

        about.center=CGPointMake(29, 451);
        privacyPolicy.center=CGPointMake(29, 481);
        termsOfUse.center=CGPointMake(29, 511);
        self.containerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"background_letter.png"]]];

        [self.containerView addSubview:about];
        [self.containerView addSubview:privacyPolicy];
        [self.containerView addSubview:termsOfUse];
    }

1 Answers1

1

Add the setContentSize to viewWillAppear or viewDidAppear.

IBOutlets only get created when the view is about to be shown, not after loading.

You can verify this by adding a breakpoint to that line. The scroll view will be nil.

Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76