How can I use UIScrollView?

How to use UIScrollView ? please give me a simple example with one scrollable image?

+6
source share
7 answers

This may be one example. We basically create a scrollview, set its frame, add content as a preview, and then set the content size. The image (iphone.png) is lower than the iphone screen so we can scroll it.

 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)]; UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iphone.png"]]; [scrollView addSubview:imageView]; [imageView release]; scrollView.contentSize = CGSizeMake(imageView.image.size.width, imageView.image.size.height); [window addSubview:scrollView]; [scrollView release]; 
+2
source

Check out an example of Apple apps:

And, of course, Apple's official documentation:

+1
source
+1
source

Here is a link for all good tutorials: Code Link

This link explains the basic steps to use: Steps by link

This is an example of scrollview with one scrollable image using XIB and several lines of code: scrollview with xib
thanks

+1
source

You can use the code below to add a UIScrollView to your view: -

 [self.ScrollView setContentSize:(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height))]; 

Step: 1 Create a UiScrollView,

 @interface ViewController : UIViewController @property (strong, nonatomic) IBOutlet UIScrollView *MyScrollView; @end 

Step 2: In your ViewController.m,

 [self.MyScrollView setContentSize:(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height))]; 
+1
source

Add UIImageView to UIScrollView .

then

Using

 imageView.image = [UIImage imageNamed:@"image1.png"]; imageView.frame = CGRectMake(0.0, 0.0, imageView.image.size.width, imageView.image.size.height); scrollView.contentSize = CGSizeMake(imageView.image.size.width, imageView.image.size.height); 
0
source

Source: https://habr.com/ru/post/887273/


All Articles