UIScrollView contentSize not working

前端 未结 15 1584
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 06:18

I put a UIScrollView in my nib\'s view, and linked it to a an IBOutlet property.

Now, when I do this in my viewDidLoad

15条回答
  •  孤城傲影
    2020-11-28 07:09

    You can use this lines of code into your *.m file's

    - (void)viewDidLoad{
       [scroll setContentSize:CGSizeMake(320, 800)]   ;
       [scroll setScrollEnabled:TRUE];
       [scroll setShowsVerticalScrollIndicator:NO];
       [scroll setShowsHorizontalScrollIndicator:YES];
    }    
    

    for this you need to take an IBOutlet property of UIScrollView into your *.h file this way:

    IBOutlet UIScrollView *scroll;
    

    And connect this from Storyboard.

    Or,

    You can use this method into your *.m file:

    -(void)viewDidLayoutSubviews 
    {
      [scroll setContentSize:CGSizeMake(320, self.view.frame.size.height* 1.5)];
       // this will pick height automatically from device's height and multiply it with 1.5  
    }
    

    This both solution works for me in xcode-5, xcode-6, xcode-6.1, xcode-6.2

提交回复
热议问题