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

Can set failure image which will be displayed in case of error #272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Classes/IDMPhotoBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
@property (nonatomic, weak) UIImage *leftArrowImage, *leftArrowSelectedImage;
@property (nonatomic, weak) UIImage *rightArrowImage, *rightArrowSelectedImage;
@property (nonatomic, weak) UIImage *actionButtonImage, *actionButtonSelectedImage;
@property (nonatomic, strong) UIImage *failureImage;

// View customization
@property (nonatomic) BOOL displayDoneButton;
Expand Down
2 changes: 2 additions & 0 deletions Classes/IDMPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ @implementation IDMPhotoBrowser
// Properties
@synthesize displayDoneButton = _displayDoneButton, displayToolbar = _displayToolbar, displayActionButton = _displayActionButton, displayCounterLabel = _displayCounterLabel, useWhiteBackgroundColor = _useWhiteBackgroundColor, doneButtonImage = _doneButtonImage;
@synthesize leftArrowImage = _leftArrowImage, rightArrowImage = _rightArrowImage, leftArrowSelectedImage = _leftArrowSelectedImage, rightArrowSelectedImage = _rightArrowSelectedImage, actionButtonImage = _actionButtonImage, actionButtonSelectedImage = _actionButtonSelectedImage;
@synthesize failureImage = _failureImage;
@synthesize displayArrowButton = _displayArrowButton, actionButtonTitles = _actionButtonTitles;
@synthesize arrowButtonsChangePhotosAnimated = _arrowButtonsChangePhotosAnimated;
@synthesize forceHideStatusBar = _forceHideStatusBar;
Expand Down Expand Up @@ -997,6 +998,7 @@ - (void)tilePages {
page = [[IDMZoomingScrollView alloc] initWithPhotoBrowser:self];
page.backgroundColor = [UIColor clearColor];
page.opaque = YES;
page.failureImage = self.failureImage;

[self configurePage:page forIndex:index];
[_visiblePages addObject:page];
Expand Down
4 changes: 4 additions & 0 deletions Classes/IDMZoomingScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
IDMTapDetectingView *_tapView; // for background taps

DACircularProgressView *_progressView;
UIImageView *_failureView;
UIImage *_failureImage;
}

@property (nonatomic, strong) IDMTapDetectingImageView *photoImageView;
@property (nonatomic, strong) UIImageView *failureView;
@property (nonatomic, strong) UIImage *failureImage;
@property (nonatomic, strong) IDMCaptionView *captionView;
@property (nonatomic, strong) id<IDMPhoto> photo;
@property (nonatomic) CGFloat maximumDoubleTapZoomScale;
Expand Down
10 changes: 10 additions & 0 deletions Classes/IDMZoomingScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ - (void)handleDoubleTap:(CGPoint)touchPoint;
@implementation IDMZoomingScrollView

@synthesize photoImageView = _photoImageView, photoBrowser = _photoBrowser, photo = _photo, captionView = _captionView;
@synthesize failureView = _failureView, failureImage = _failureImage;

- (id)initWithPhotoBrowser:(IDMPhotoBrowser *)browser {
if ((self = [super init])) {
Expand Down Expand Up @@ -66,6 +67,10 @@ - (id)initWithPhotoBrowser:(IDMPhotoBrowser *)browser {
_progressView.trackTintColor = browser.trackTintColor ? self.photoBrowser.trackTintColor : [UIColor colorWithWhite:0.2 alpha:1];
_progressView.progressTintColor = browser.progressTintColor ? self.photoBrowser.progressTintColor : [UIColor colorWithWhite:1.0 alpha:1];
[self addSubview:_progressView];

_failureView = [[UIImageView alloc] init];
_failureView.contentMode = UIViewContentModeCenter;
[self addSubview:_failureView];

// Setup
self.backgroundColor = [UIColor clearColor];
Expand Down Expand Up @@ -105,6 +110,8 @@ - (void)displayImage {

self.contentSize = CGSizeMake(0, 0);

_failureView.hidden = YES;

// Get image from browser as it handles ordering of fetching
UIImage *img = [self.photoBrowser imageForPhoto:_photo];
if (img) {
Expand Down Expand Up @@ -149,6 +156,9 @@ - (void)setProgress:(CGFloat)progress forPhoto:(IDMPhoto*)photo {

// Image failed so just show black!
- (void)displayImageFailure {
_failureView.hidden = NO;
_failureView.frame = self.bounds;
_failureView.image = self.failureImage;
[_progressView removeFromSuperview];
}

Expand Down