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

Added SFSymbols to iOS 13 and above #455

Merged
merged 2 commits into from
Dec 15, 2020
Merged
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
46 changes: 44 additions & 2 deletions Objective-C/TOCropViewController/Views/TOCropToolbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ - (void)setup {
nil)
forState:UIControlStateNormal];
[_doneTextButton setTitleColor:[UIColor colorWithRed:1.0f green:0.8f blue:0.0f alpha:1.0f] forState:UIControlStateNormal];
[_doneTextButton.titleLabel setFont:[UIFont systemFontOfSize:17.0f]];
if (@available(iOS 13.0, *)) {
[_doneTextButton.titleLabel setFont:[UIFont systemFontOfSize:17.0f weight:UIFontWeightMedium]];
} else {
[_doneTextButton.titleLabel setFont:[UIFont systemFontOfSize:17.0f]];
}
[_doneTextButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
[_doneTextButton sizeToFit];
[self addSubview:_doneTextButton];
Expand Down Expand Up @@ -284,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 @@ -407,6 +415,11 @@ - (void)setDoneTextButtonTitle:(NSString *)doneTextButtonTitle {
#pragma mark - Image Generation -
+ (UIImage *)doneImage
{
if (@available(iOS 13.0, *)) {
return [UIImage systemImageNamed:@"checkmark"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]];
}

UIImage *doneImage = nil;

UIGraphicsBeginImageContextWithOptions((CGSize){17,14}, NO, 0.0f);
Expand All @@ -430,6 +443,11 @@ + (UIImage *)doneImage

+ (UIImage *)cancelImage
{
if (@available(iOS 13.0, *)) {
return [UIImage systemImageNamed:@"xmark"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]];
}

UIImage *cancelImage = nil;

UIGraphicsBeginImageContextWithOptions((CGSize){16,16}, NO, 0.0f);
Expand Down Expand Up @@ -459,6 +477,12 @@ + (UIImage *)cancelImage

+ (UIImage *)rotateCCWImage
{
if (@available(iOS 13.0, *)) {
return [[UIImage systemImageNamed:@"rotate.left.fill"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]]
imageWithBaselineOffsetFromBottom:4];
}

UIImage *rotateImage = nil;

UIGraphicsBeginImageContextWithOptions((CGSize){18,21}, NO, 0.0f);
Expand Down Expand Up @@ -496,6 +520,12 @@ + (UIImage *)rotateCCWImage

+ (UIImage *)rotateCWImage
{
if (@available(iOS 13.0, *)) {
return [[UIImage systemImageNamed:@"rotate.right.fill"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]]
imageWithBaselineOffsetFromBottom:4];
}

UIImage *rotateCCWImage = [self.class rotateCCWImage];
UIGraphicsBeginImageContextWithOptions(rotateCCWImage.size, NO, rotateCCWImage.scale);
CGContextRef context = UIGraphicsGetCurrentContext();
Expand All @@ -509,6 +539,12 @@ + (UIImage *)rotateCWImage

+ (UIImage *)resetImage
{
if (@available(iOS 13.0, *)) {
return [[UIImage systemImageNamed:@"arrow.counterclockwise"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]]
imageWithBaselineOffsetFromBottom:0];;
}

UIImage *resetImage = nil;

UIGraphicsBeginImageContextWithOptions((CGSize){22,18}, NO, 0.0f);
Expand Down Expand Up @@ -553,6 +589,12 @@ + (UIImage *)resetImage

+ (UIImage *)clampImage
{
if (@available(iOS 13.0, *)) {
return [[UIImage systemImageNamed:@"aspectratio.fill"
withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]]
imageWithBaselineOffsetFromBottom:0];
}

UIImage *clampImage = nil;

UIGraphicsBeginImageContextWithOptions((CGSize){22,16}, NO, 0.0f);
Expand Down