-4

How to create a simple scroll view when clicking a button in Xcode?

I have assigned the button and gave IBAction as press, what to code to make a scroll view on this action?

 -(IBAction)press
 {

 }
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    Possible duplicate of [How to create a UIScrollView Programmatically?](https://stackoverflow.com/questions/2998336/how-to-create-a-uiscrollview-programmatically) – Cœur Nov 22 '18 at 17:58
  • Possible duplicate of [Add UIScrollView in UIView programmatically](https://stackoverflow.com/questions/16035115/add-uiscrollview-in-uiview-programmatically) – Cœur Nov 22 '18 at 18:00
  • Possible duplicate of [Implementing UIScrollView programmatically](https://stackoverflow.com/questions/8909347/implementing-uiscrollview-programmatically) – Cœur Nov 22 '18 at 18:01
  • Possible duplicate of [add uiscrollview programmatically](https://stackoverflow.com/questions/9186439/add-uiscrollview-programmatically) – Cœur Nov 22 '18 at 18:02
  • Possible duplicate of [Creating UIScrollView Programmatically](https://stackoverflow.com/questions/17223707/creating-uiscrollview-programmatically) – Cœur Nov 22 '18 at 18:03

1 Answers1

0

In .h file you must add delegate definition to your class declaration - something like this:

@interface someClass : NSObject <UIScrollViewDelegate>

In .m write somethink like this:

 -(IBAction)press
 {
    UIScrollView *_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    _scrollView.backgroundColor = [UIColor clearColor];
    _scrollView.userInteractionEnabled = YES;
    _scrollView.delegate = nil;

    [self.view addSubview:self.scrollView];
}

That's all! :)

Sergei Nikitin
  • 788
  • 7
  • 12