-
Notifications
You must be signed in to change notification settings - Fork 383
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
Changes from 20 commits
0bdbe40
b1319cd
0fdaf3a
389b562
1e825d9
cefbcb3
294848f
ee159d3
3070605
a9e7aa5
bee2378
055ca60
e7230df
f88bad8
f29731d
11b47eb
81c1014
20eca18
a5a5441
7c59992
162e0ba
4acbeeb
5d1a27d
211d897
0cd6a1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
#import "NYTExamplePhoto.h" | ||
|
||
static const NSUInteger NYTViewControllerCustomEverythingPhotoIndex = 1; | ||
static const NSUInteger NYTViewControllerLongCaptionPhotoIndex = 2; | ||
static const NSUInteger NYTViewControllerDefaultLoadingSpinnerPhotoIndex = 3; | ||
static const NSUInteger NYTViewControllerNoReferenceViewPhotoIndex = 4; | ||
static const NSUInteger NYTViewControllerCustomMaxZoomScalePhotoIndex = 5; | ||
|
@@ -62,10 +63,28 @@ + (NSArray *)newTestPhotos { | |
if (i == NYTViewControllerCustomEverythingPhotoIndex) { | ||
photo.placeholderImage = [UIImage imageNamed:@"NYTimesBuildingPlaceholder"]; | ||
} | ||
|
||
NSString *caption = @"summary"; | ||
if (i == NYTViewControllerCustomEverythingPhotoIndex) { | ||
caption = @"photo with custom everything"; | ||
} | ||
else if (i == NYTViewControllerLongCaptionPhotoIndex) { | ||
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."; | ||
} | ||
else if (i == NYTViewControllerDefaultLoadingSpinnerPhotoIndex) { | ||
caption = @"photo with loading spinner"; | ||
} | ||
else if (i == NYTViewControllerNoReferenceViewPhotoIndex) { | ||
caption = @"photo without reference view"; | ||
} | ||
else if (i == NYTViewControllerCustomMaxZoomScalePhotoIndex) { | ||
caption = @"photo with custom maximum zoom scale"; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
// | ||
|
||
#import "NYTPhotosOverlayView.h" | ||
#import "NYTPhotoCaptionViewLayoutWidthHinting.h" | ||
|
||
@interface NYTPhotosOverlayView () | ||
|
||
|
@@ -49,6 +50,10 @@ - (void)layoutSubviews { | |
}]; | ||
|
||
[super layoutSubviews]; | ||
|
||
if ([self.captionView respondsToSelector:@selector(setPreferredMaxLayoutWidth:)]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure. Here are some arguments for and against changing to for
against
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I asked because I assumed that was the point of adding the protocol in the first place. If you're just interested in the caption view responding to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So that I have something to cast to on the next line: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated my comment with this line after you posted yours:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's really the best answer for "why check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
well, I'll be! the comment on that function doesn't include a note about locking…I guess I should send a PR :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That said, would something like that be considered an implementation detail if it's not mentioned in any documentation apart from the source code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is all implementation detail! And I think I am sufficiently convinced not to micro-optimize this for now (though I suspect that this cache lookup will almost always succeed); see 162e0ba |
||
[(id<NYTPhotoCaptionViewLayoutWidthHinting>) self.captionView setPreferredMaxLayoutWidth:self.bounds.size.width]; | ||
} | ||
} | ||
|
||
#pragma mark - NYTPhotosOverlayView | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// NYTPhotoCaptionViewLayoutWidthHinting.h | ||
// NYTPhotoViewer | ||
// | ||
// Created by Chris Dzombak on 10/30/15. | ||
// | ||
// | ||
|
||
@import Foundation; | ||
@import UIKit; | ||
|
||
/** | ||
* Allows a view to opt-in to receiving a hint of its layout width. This aids in calculating an appropriate intrinsic content size. | ||
*/ | ||
@protocol NYTPhotoCaptionViewLayoutWidthHinting <NSObject> | ||
|
||
/** | ||
* The preferred maximum width, in points, of this caption view. | ||
* | ||
* This property works exactly as it does on `UILabel`. | ||
* | ||
* This property affects the size of the view when layout constraints are applied to it. During layout, if the text extends beyond the width specified by this property, the additional text is flowed to one or more new lines, thereby increasing the height of the view. | ||
*/ | ||
@property (nonatomic) CGFloat preferredMaxLayoutWidth; | ||
|
||
@end | ||
|
||
@interface UILabel (NYTPhotoCaptionViewLayoutWidthHinting) <NYTPhotoCaptionViewLayoutWidthHinting> | ||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious as to why not just make these static ints an enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¯_(ツ)_/¯ they were static ints before, and slowly we've added a few more special cases.