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

delegate method to customize title text #142

Merged
merged 1 commit into from
Jan 28, 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: 11 additions & 0 deletions Pod/Classes/ios/NYTPhotosViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification;
*/
- (UIView * _Nullable)photosViewController:(NYTPhotosViewController *)photosViewController captionViewForPhoto:(id <NYTPhoto>)photo;

/**
* Returns a string to display as the title of a photo.
*
* @param photosViewController The `NYTPhotosViewController` instance that sent the delegate message.
* @param photo The photo object over which to display the title.
* @param photoIndex The index of the photo.
*
* @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.
*/
- (NSString * _Nullable)photosViewController:(NYTPhotosViewController *)photosViewController titleForPhoto:(id <NYTPhoto>)photo atIndex:(NSUInteger)photoIndex;

/**
* 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
20 changes: 14 additions & 6 deletions Pod/Classes/ios/NYTPhotosViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,25 @@ - (void)addOverlayView {
[self setOverlayViewHidden:YES animated:NO];
}


- (void)updateOverlayInformation {
NSUInteger displayIndex = 1;
NSString *overlayTitle;

NSUInteger photoIndex = [self.dataSource indexOfPhoto:self.currentlyDisplayedPhoto];
if (photoIndex < self.dataSource.numberOfPhotos) {
displayIndex = photoIndex + 1;

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

NSString *overlayTitle;
if (self.dataSource.numberOfPhotos > 1) {
overlayTitle = [NSString localizedStringWithFormat:NSLocalizedString(@"%lu of %lu", nil), (unsigned long)displayIndex, (unsigned long)self.dataSource.numberOfPhotos];
if (!overlayTitle) {
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];
}
}

self.overlayView.title = overlayTitle;
Expand Down