Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify how title-text delegate method is intended to be used #151

Merged
merged 5 commits into from
Feb 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Example/NYTPhotoViewer/NYTViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ - (void)updateImagesOnPhotosViewController:(NYTPhotosViewController *)photosView
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(updateImageDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
for (NYTExamplePhoto *photo in photos) {
if (!photo.image && !photo.imageData) {
// Photo credit: Nic Lehoux
photo.image = [UIImage imageNamed:@"NYTimesBuilding"];
[photosViewController updateImageForPhoto:photo];
}
Expand Down Expand Up @@ -99,7 +98,7 @@ + (NSArray *)newTestPhotos {

photo.attributedCaptionTitle = [[NSAttributedString alloc] initWithString:@(i + 1).stringValue attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody]}];
photo.attributedCaptionSummary = [[NSAttributedString alloc] initWithString:caption attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor], NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody]}];
photo.attributedCaptionCredit = [[NSAttributedString alloc] initWithString:@"credit" attributes:@{NSForegroundColorAttributeName: [UIColor grayColor], NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]}];
photo.attributedCaptionCredit = [[NSAttributedString alloc] initWithString:@"NYT Building Photo Credit: Nic Lehoux" attributes:@{NSForegroundColorAttributeName: [UIColor grayColor], NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]}];

[photos addObject:photo];
}
Expand Down Expand Up @@ -156,6 +155,14 @@ - (NSDictionary *)photosViewController:(NYTPhotosViewController *)photosViewCont
return nil;
}

- (NSString *)photosViewController:(NYTPhotosViewController *)photosViewController titleForPhoto:(id<NYTPhoto>)photo atIndex:(NSUInteger)photoIndex totalPhotoCount:(NSUInteger)totalPhotoCount {
if ([photo isEqual:self.photos[NYTViewControllerPhotoIndexCustomEverything]]) {
return [NSString stringWithFormat:@"%lu/%lu", (unsigned long)photoIndex+1, (unsigned long)totalPhotoCount];
}

return nil;
}

- (void)photosViewController:(NYTPhotosViewController *)photosViewController didNavigateToPhoto:(id <NYTPhoto>)photo atIndex:(NSUInteger)photoIndex {
NSLog(@"Did Navigate To Photo: %@ identifier: %lu", photo, (unsigned long)photoIndex);
}
Expand Down
11 changes: 7 additions & 4 deletions Pod/Classes/ios/NYTPhotosViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,18 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification;
- (UIView * _Nullable)photosViewController:(NYTPhotosViewController *)photosViewController captionViewForPhoto:(id <NYTPhoto>)photo;

/**
* Returns a string to display as the title of a photo.
* Returns a string to display as the title in the navigation-bar area for a photo.
*
* This small area of the screen is not intended to display a caption or similar information about the photo itself. (NYTPhotoViewer is designed to provide this information in the capton view, and as such the `NYTPhoto` protocol provides properties for the title, summary, and credit for each photo.) Instead, consider using this delegate method to customize how your app displays the user's progress through a set of photos.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

information in the capton view

Typo here.

*
* @param photosViewController The `NYTPhotosViewController` instance that sent the delegate message.
* @param photo The photo object over which to display the title.
* @param photo The photo object for which to display the title.
* @param photoIndex The index of the photo.
* @param totalPhotoCount The number of photos beign displayed by the photo viewer.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

photos beign displayed

Typo here.

*
* @return The text to display as the title for the corresponding photo. Return `nil` to show a default title of the current photo index and the total number of photos.
* @return The text to display as the navigation-item title for the given photo. Return `nil` to show a default title like "1 of 4" indicating progress in a slideshow, or an empty string to hide this text entirely.
*/
- (NSString * _Nullable)photosViewController:(NYTPhotosViewController *)photosViewController titleForPhoto:(id <NYTPhoto>)photo atIndex:(NSUInteger)photoIndex;
- (NSString * _Nullable)photosViewController:(NYTPhotosViewController *)photosViewController titleForPhoto:(id <NYTPhoto>)photo atIndex:(NSUInteger)photoIndex totalPhotoCount:(NSUInteger)totalPhotoCount;

/**
* Returns a view to display while a photo is loading. Can be any `UIView` object, but is expected to respond to `sizeToFit` appropriately. This view will be sized and centered in the blank area, and hidden when the photo image is loaded.
Expand Down
11 changes: 5 additions & 6 deletions Pod/Classes/ios/NYTPhotosViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,18 @@ - (void)updateOverlayInformation {

NSUInteger photoIndex = [self.dataSource indexOfPhoto:self.currentlyDisplayedPhoto];

if ([self.delegate respondsToSelector:@selector(photosViewController:titleForPhoto:atIndex:)]) {
overlayTitle = [self.delegate photosViewController:self titleForPhoto:self.currentlyDisplayedPhoto atIndex:photoIndex];
if ([self.delegate respondsToSelector:@selector(photosViewController:titleForPhoto:atIndex:totalPhotoCount:)]) {
overlayTitle = [self.delegate photosViewController:self titleForPhoto:self.currentlyDisplayedPhoto atIndex:photoIndex totalPhotoCount:self.dataSource.numberOfPhotos];
}

if (!overlayTitle) {
if (!overlayTitle && self.dataSource.numberOfPhotos > 1) {
NSUInteger displayIndex = 1;

if (photoIndex < self.dataSource.numberOfPhotos) {
displayIndex = photoIndex + 1;
}
if (self.dataSource.numberOfPhotos > 1) {
overlayTitle = [NSString localizedStringWithFormat:NSLocalizedString(@"%lu of %lu", nil), (unsigned long)displayIndex, (unsigned long)self.dataSource.numberOfPhotos];
}

overlayTitle = [NSString localizedStringWithFormat:NSLocalizedString(@"%lu of %lu", nil), (unsigned long)displayIndex, (unsigned long)self.dataSource.numberOfPhotos];
}

self.overlayView.title = overlayTitle;
Expand Down