Skip to content

Commit

Permalink
Fix "aspectSizeThatFits" padding.
Browse files Browse the repository at this point in the history
  • Loading branch information
vlfm committed Sep 27, 2014
1 parent ef1c20f commit 236c835
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/VFAspectRatio.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@ - (instancetype)initWithWidth:(NSInteger)width height:(NSInteger)height {
}

- (CGSize)aspectSizeThatFits:(CGSize)size padding:(CGFloat)padding {
CGFloat cut = padding * 2;
CGSize paddedSize = CGSizeMake(size.width - cut, size.height - cut);
return [self aspectSizeThatFits:paddedSize];
}

- (CGSize)aspectSizeThatFits:(CGSize)size {
CGFloat w = 0;
CGFloat h = 0;

if (_width == _height) {
w = MIN(size.width, size.height) - padding;
w = MIN(size.width, size.height);
h = w;
} else if (_width > _height) {
w = size.width - padding;
w = size.width;
h = (w / _width) * _height;
} else {
h = size.height - padding;
h = size.height;
w = (h / _height) * _width;
}

Expand Down

0 comments on commit 236c835

Please sign in to comment.