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

Use scrolling UITextView for captions #88

Merged
merged 25 commits into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0bdbe40
Add an example photo with extremely long caption
cdzombak Oct 30, 2015
b1319cd
Attach font sizes to captions in Example app
cdzombak Oct 30, 2015
0fdaf3a
Use UITextView for NYTPhotoCaptionView
cdzombak Oct 30, 2015
389b562
Reduce caption margins since UITextView has line fragment padding bui…
cdzombak Oct 30, 2015
1e825d9
First pass at PhotoCaptionView intrinsic content size with a text view
cdzombak Oct 30, 2015
cefbcb3
Second pass at calculating caption content size
cdzombak Oct 30, 2015
294848f
Give caption views a hint about their layout widths
cdzombak Oct 30, 2015
ee159d3
Extract NYTPhotoCaptionViewLayoutWidthHinting protocol to its own file
cdzombak Oct 30, 2015
3070605
`pod install` in Example app
cdzombak Oct 30, 2015
a9e7aa5
Use relative, not hardcoded, max caption height
cdzombak Oct 30, 2015
bee2378
Add caption max height constraint from _our_ caption class
cdzombak Oct 30, 2015
055ca60
Mark PhotoCaptionView as requiring constraint-based layout
cdzombak Nov 2, 2015
e7230df
PhotoCaptionView takes only 30% of height
cdzombak Nov 2, 2015
f88bad8
Resolve iOS 8.x gradient-layer layout bug
cdzombak Nov 2, 2015
f29731d
Eliminate added vertical padding on PhotoCaptionView
cdzombak Nov 2, 2015
11b47eb
Merge remote-tracking branch 'origin/develop' into cdz/scroll-captions
cdzombak Nov 2, 2015
81c1014
Standardize PhotoCaptionView.preferredMaxLayoutWidth on setting it
cdzombak Nov 2, 2015
20eca18
Use textContainerInsets for padding PhotoCaptionView
cdzombak Nov 2, 2015
a5a5441
[minor] update forgotten header comments
cdzombak Nov 2, 2015
7c59992
[minor] fix misspelled constant in PhotosViewController
cdzombak Nov 2, 2015
162e0ba
Check for protocol conformance, not a specific method, before casting
cdzombak Nov 2, 2015
4acbeeb
Use an enum for example photo indices
cdzombak Nov 3, 2015
5d1a27d
Merge remote-tracking branch 'origin/develop' into cdz/scroll-captions
cdzombak Jan 4, 2016
211d897
Resolve warning about unhandled case in Example project
cdzombak Jan 4, 2016
0cd6a1e
Merge remote-tracking branch 'origin/develop' into cdz/scroll-captions
cdzombak Jan 7, 2016
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
68 changes: 49 additions & 19 deletions Example/NYTPhotoViewer/NYTViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
#import <NYTPhotoViewer/NYTPhotosViewController.h>
#import "NYTExamplePhoto.h"

static const NSUInteger NYTViewControllerCustomEverythingPhotoIndex = 1;
static const NSUInteger NYTViewControllerDefaultLoadingSpinnerPhotoIndex = 3;
static const NSUInteger NYTViewControllerNoReferenceViewPhotoIndex = 4;
static const NSUInteger NYTViewControllerCustomMaxZoomScalePhotoIndex = 5;
typedef NS_ENUM(NSUInteger, NYTViewControllerPhotoIndex) {
NYTViewControllerPhotoIndexCustomEverything = 1,
NYTViewControllerPhotoIndexLongCaption = 2,
NYTViewControllerPhotoIndexDefaultLoadingSpinner = 3,
NYTViewControllerPhotoIndexNoReferenceView = 4,
NYTViewControllerPhotoIndexCustomMaxZoomScale = 5,
NYTViewControllerPhotoIndexGif = 6,
NYTViewControllerPhotoCount,
};

@interface NYTViewController () <NYTPhotosViewControllerDelegate>

Expand Down Expand Up @@ -51,26 +56,51 @@ - (void)updateImagesOnPhotosViewController:(NYTPhotosViewController *)photosView
+ (NSArray *)newTestPhotos {
NSMutableArray *photos = [NSMutableArray array];

int limit = 7;
for (int i = 0; i < limit; i++) {
for (NSUInteger i = 0; i < NYTViewControllerPhotoCount; i++) {
NYTExamplePhoto *photo = [[NYTExamplePhoto alloc] init];

if (i == limit - 1) {
if (i == NYTViewControllerPhotoIndexGif) {
photo.imageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"giphy" ofType:@"gif"]];
} else if (i == NYTViewControllerPhotoIndexCustomEverything || i == NYTViewControllerPhotoIndexDefaultLoadingSpinner) {
// no-op, left here for clarity:
photo.image = nil;
} else {
photo.image = [UIImage imageNamed:@"NYTimesBuilding"];
}
if (i == NYTViewControllerCustomEverythingPhotoIndex || i == NYTViewControllerDefaultLoadingSpinnerPhotoIndex) {
photo.image = nil;
}

if (i == NYTViewControllerCustomEverythingPhotoIndex) {
if (i == NYTViewControllerPhotoIndexCustomEverything) {
photo.placeholderImage = [UIImage imageNamed:@"NYTimesBuildingPlaceholder"];
}

NSString *caption = @"summary";
switch ((NYTViewControllerPhotoIndex)i) {
case NYTViewControllerPhotoIndexCustomEverything:
caption = @"photo with custom everything";
break;
case NYTViewControllerPhotoIndexLongCaption:
caption = @"photo with long caption. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum maximus laoreet vehicula. Maecenas elit quam, pellentesque at tempor vel, tempus non sem. Vestibulum ut aliquam elit. Vivamus rhoncus sapien turpis, at feugiat augue luctus id. Nulla mi urna, viverra sed augue malesuada, bibendum bibendum massa. Cras urna nibh, lacinia vitae feugiat eu, consectetur a tellus. Morbi venenatis nunc sit amet varius pretium. Duis eget sem nec nulla lobortis finibus. Nullam pulvinar gravida est eget tristique. Curabitur faucibus nisl eu diam ullamcorper, at pharetra eros dictum. Suspendisse nibh urna, ultrices a augue a, euismod mattis felis. Ut varius tortor ac efficitur pellentesque. Mauris sit amet rhoncus dolor. Proin vel porttitor mi. Pellentesque lobortis interdum turpis, vitae tincidunt purus vestibulum vel. Phasellus tincidunt vel mi sit amet congue.";
break;
case NYTViewControllerPhotoIndexDefaultLoadingSpinner:
caption = @"photo with loading spinner";
break;
case NYTViewControllerPhotoIndexNoReferenceView:
caption = @"photo without reference view";
break;
case NYTViewControllerPhotoIndexCustomMaxZoomScale:
caption = @"photo with custom maximum zoom scale";
break;
case NYTViewControllerPhotoIndexGif:
caption = @"animated GIF";
break;
case NYTViewControllerPhotoCount:
// this case statement intentionally left blank.
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

again mostly curious, but this seems like a good place for a switch statement to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, especially if these were an enum.


photo.attributedCaptionTitle = [[NSAttributedString alloc] initWithString:@(i + 1).stringValue attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
photo.attributedCaptionSummary = [[NSAttributedString alloc] initWithString:@"summary" attributes:@{NSForegroundColorAttributeName: [UIColor grayColor]}];
photo.attributedCaptionCredit = [[NSAttributedString alloc] initWithString:@"credit" attributes:@{NSForegroundColorAttributeName: [UIColor darkGrayColor]}];
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]}];

[photos addObject:photo];
}

Expand All @@ -80,15 +110,15 @@ + (NSArray *)newTestPhotos {
#pragma mark - NYTPhotosViewControllerDelegate

- (UIView *)photosViewController:(NYTPhotosViewController *)photosViewController referenceViewForPhoto:(id <NYTPhoto>)photo {
if ([photo isEqual:self.photos[NYTViewControllerNoReferenceViewPhotoIndex]]) {
if ([photo isEqual:self.photos[NYTViewControllerPhotoIndexNoReferenceView]]) {
return nil;
}

return self.imageButton;
}

- (UIView *)photosViewController:(NYTPhotosViewController *)photosViewController loadingViewForPhoto:(id <NYTPhoto>)photo {
if ([photo isEqual:self.photos[NYTViewControllerCustomEverythingPhotoIndex]]) {
if ([photo isEqual:self.photos[NYTViewControllerPhotoIndexCustomEverything]]) {
UILabel *loadingLabel = [[UILabel alloc] init];
loadingLabel.text = @"Custom Loading...";
loadingLabel.textColor = [UIColor greenColor];
Expand All @@ -99,7 +129,7 @@ - (UIView *)photosViewController:(NYTPhotosViewController *)photosViewController
}

- (UIView *)photosViewController:(NYTPhotosViewController *)photosViewController captionViewForPhoto:(id <NYTPhoto>)photo {
if ([photo isEqual:self.photos[NYTViewControllerCustomEverythingPhotoIndex]]) {
if ([photo isEqual:self.photos[NYTViewControllerPhotoIndexCustomEverything]]) {
UILabel *label = [[UILabel alloc] init];
label.text = @"Custom Caption View";
label.textColor = [UIColor whiteColor];
Expand All @@ -111,15 +141,15 @@ - (UIView *)photosViewController:(NYTPhotosViewController *)photosViewController
}

- (CGFloat)photosViewController:(NYTPhotosViewController *)photosViewController maximumZoomScaleForPhoto:(id <NYTPhoto>)photo {
if ([photo isEqual:self.photos[NYTViewControllerCustomMaxZoomScalePhotoIndex]]) {
if ([photo isEqual:self.photos[NYTViewControllerPhotoIndexCustomMaxZoomScale]]) {
return 10.0f;
}

return 1.0f;
}

- (NSDictionary *)photosViewController:(NYTPhotosViewController *)photosViewController overlayTitleTextAttributesForPhoto:(id <NYTPhoto>)photo {
if ([photo isEqual:self.photos[NYTViewControllerCustomEverythingPhotoIndex]]) {
if ([photo isEqual:self.photos[NYTViewControllerPhotoIndexCustomEverything]]) {
return @{NSForegroundColorAttributeName: [UIColor grayColor]};
}

Expand Down
8 changes: 4 additions & 4 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- FLAnimatedImage (1.0.8)
- FLAnimatedImage (1.0.10)
- NYTPhotoViewer/AnimatedGifSupport (0.1.2):
- FLAnimatedImage (= 1.0.8)
- FLAnimatedImage (~> 1.0.8)
- NYTPhotoViewer/Core
- NYTPhotoViewer/Core (0.1.2)
- OCMock (3.2)
Expand All @@ -15,8 +15,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
FLAnimatedImage: f9422f796135aff80d8c00b2afc48015bb746e24
NYTPhotoViewer: e348bfa437398deb67a88b7928e85168ac38b5df
FLAnimatedImage: e16a1e1cef08e4c509b47e4acbe3923f65c16135
NYTPhotoViewer: 06876beb4c9bc6f10a59eb8b898c480fd89f7c51
OCMock: 28def049ef47f996b515a8eeea958be7ccab2dbb

COCOAPODS: 0.39.0
82 changes: 82 additions & 0 deletions Example/Pods/FLAnimatedImage/FLAnimatedImage/FLAnimatedImage.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading