Skip to content

Commit

Permalink
Added baseline offsets to SFSymbol images
Browse files Browse the repository at this point in the history
  • Loading branch information
TimOliver committed Dec 15, 2020
1 parent 1886e4e commit 6790335
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions Objective-C/TOCropViewController/Views/TOCropToolbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,16 @@ - (void)layoutToolbarButtons:(NSArray *)buttons withSameButtonSize:(CGSize)size
CGFloat padding = (maxLength - fixedSize * count) / (count + 1);

for (NSInteger i = 0; i < count; i++) {
UIView *button = buttons[i];
UIButton *button = buttons[i];
CGFloat sameOffset = horizontally ? fabs(CGRectGetHeight(containerRect)-CGRectGetHeight(button.bounds)) : fabs(CGRectGetWidth(containerRect)-CGRectGetWidth(button.bounds));
CGFloat diffOffset = padding + i * (fixedSize + padding);
CGPoint origin = horizontally ? CGPointMake(diffOffset, sameOffset) : CGPointMake(sameOffset, diffOffset);
if (horizontally) {
origin.x += CGRectGetMinX(containerRect);
if (@available(iOS 13.0, *)) {
UIImage *image = button.imageView.image;
button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, image.baselineOffsetFromBottom, 0);
}
} else {
origin.y += CGRectGetMinY(containerRect);
}
Expand Down Expand Up @@ -474,8 +478,9 @@ + (UIImage *)cancelImage
+ (UIImage *)rotateCCWImage
{
if (@available(iOS 13.0, *)) {
return [UIImage systemImageNamed:@"rotate.left.fill"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]];
return [[UIImage systemImageNamed:@"rotate.left.fill"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]]
imageWithBaselineOffsetFromBottom:4];
}

UIImage *rotateImage = nil;
Expand Down Expand Up @@ -516,8 +521,9 @@ + (UIImage *)rotateCCWImage
+ (UIImage *)rotateCWImage
{
if (@available(iOS 13.0, *)) {
return [UIImage systemImageNamed:@"rotate.right.fill"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]];
return [[UIImage systemImageNamed:@"rotate.right.fill"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]]
imageWithBaselineOffsetFromBottom:4];
}

UIImage *rotateCCWImage = [self.class rotateCCWImage];
Expand All @@ -534,8 +540,9 @@ + (UIImage *)rotateCWImage
+ (UIImage *)resetImage
{
if (@available(iOS 13.0, *)) {
return [UIImage systemImageNamed:@"arrow.counterclockwise"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]];
return [[UIImage systemImageNamed:@"arrow.counterclockwise"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]]
imageWithBaselineOffsetFromBottom:0];;
}

UIImage *resetImage = nil;
Expand Down Expand Up @@ -583,8 +590,9 @@ + (UIImage *)resetImage
+ (UIImage *)clampImage
{
if (@available(iOS 13.0, *)) {
return [UIImage systemImageNamed:@"aspectratio.fill"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]];
return [[UIImage systemImageNamed:@"aspectratio.fill"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]]
imageWithBaselineOffsetFromBottom:0];
}

UIImage *clampImage = nil;
Expand Down

0 comments on commit 6790335

Please sign in to comment.