<

Scrolling

>

From: Apple Developer Page

Try: Raywenderlich

  1. Open MainStoryboard.storyboard and delete the scene that’s already in there by selecting the view controller (click on it on the story board) and then deleting it.
  2. Then, add a table view controller by dragging one from the Object Library on to the story board.
  3. Now select the table you added and then click Editor\Embed In\Navigation Controller.
    Select the table view within the table view controller, and set the content type to Static Cells in the attributes inspector (as shown in image below).
  4. Finally, set the number of rows in the table view section (if you don’t see it, tap on the arrow next to “Table View” in the left sidebar showing the storyboard hierarchy and then select “Table View Section”) to 4, and for each row in the table view, set its style to basic and edit the labels to read:
  • Image scroll
  • Custom view scroll
  • Paged
  • Paged with peeking
Single View Controller

Drag the UIScrollView icon located in the Library->Cocoa Touch->Data Views section of the Library palette into the view ‘window’. You then connect the UIViewController subclass’s view outlet to the scroll view.

 

ViewController.m

 

- (void)viewDidLoad
{

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

// Adjust scroll view content size, set background colour and turn on paging
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 12,
scrollView.frame.size.height);
scrollView.pagingEnabled=YES;
scrollView.backgroundColor = [UIColor blackColor];

// Generate content for our scroll view using the frame height and width as the reference
point
int i = 0;
while (i<=11) {

UIView *views = [[UIView alloc]
initWithFrame:CGRectMake(((scrollView.frame.size.width)*i)+20, 10,
(scrollView.frame.size.width)-40, scrollView.frame.size.height-20)];
views.backgroundColor=[UIColor yellowColor];
[views setTag:i];
[scrollView addSubview:views];

i++;

}

}