What Car Is This?

The final thing you need to do with the car image scene is to correctly set the car number. With paging enabled, you know how much width each car takes. You also know the location of the scroll view in the content. To find the number (not the index) of the car, find the number of page widths.

You need to add the methods in Listing 6-5 above viewDidLoad:. The methods update the label and find the current car index. The car index is 0-based, so add 1 before displaying.

Listing 6-5 Updating the Label Using the Index of the Current Car Image

- (void) updateCarNumberLabel {     NSInteger carIndex = [self carIndexForPoint:self.scrollView.contentOffset];     NSString *newText = [NSString stringWithFormat:@"Car ...

Get Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.