Skip to content
Merged
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
7 changes: 7 additions & 0 deletions Objective-C/TOCropViewController/TOCropViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@
*/
@property (nullable, nonatomic, copy) NSString *cancelButtonTitle;

/**
If true, button icons are visible in portairt instead button text.

Default is NO.
*/
@property (nonatomic, assign) BOOL showOnlyIcons;

/**
Color for the 'Done' button.
Setting this will override the default color.
Expand Down
4 changes: 4 additions & 0 deletions Objective-C/TOCropViewController/TOCropViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,10 @@ - (void)setCancelButtonTitle:(NSString *)title
self.toolbar.cancelTextButtonTitle = title;
}

- (void)setShowOnlyIcons:(BOOL)showOnlyIcons {
self.toolbar.showOnlyIcons = showOnlyIcons;
}

- (void)setDoneButtonColor:(UIColor *)color {
self.toolbar.doneButtonColor = color;
}
Expand Down
2 changes: 2 additions & 0 deletions Objective-C/TOCropViewController/Views/TOCropToolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) NSString *cancelTextButtonTitle;
@property (nonatomic, copy) UIColor *cancelButtonColor;

@property (nonatomic, assign) BOOL showOnlyIcons;

/* The cropper control buttons */
@property (nonatomic, strong, readonly) UIButton *rotateCounterclockwiseButton;
@property (nonatomic, strong, readonly) UIButton *resetButton;
Expand Down
32 changes: 21 additions & 11 deletions Objective-C/TOCropViewController/Views/TOCropToolbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ - (void)layoutSubviews
BOOL verticalLayout = (CGRectGetWidth(self.bounds) < CGRectGetHeight(self.bounds));
CGSize boundsSize = self.bounds.size;

self.cancelIconButton.hidden = self.cancelButtonHidden || (!verticalLayout);
self.cancelTextButton.hidden = self.cancelButtonHidden || (verticalLayout);
self.doneIconButton.hidden = self.doneButtonHidden || (!verticalLayout);
self.doneTextButton.hidden = self.doneButtonHidden || (verticalLayout);
self.cancelIconButton.hidden = self.cancelButtonHidden || (_showOnlyIcons ? false : !verticalLayout);
self.cancelTextButton.hidden = self.cancelButtonHidden || (_showOnlyIcons ? true : verticalLayout);
self.doneIconButton.hidden = self.doneButtonHidden || (_showOnlyIcons ? false : !verticalLayout);
self.doneTextButton.hidden = self.doneButtonHidden || (_showOnlyIcons ? true : verticalLayout);

CGRect frame = self.bounds;
frame.origin.x -= self.backgroundViewOutsets.left;
Expand All @@ -178,7 +178,7 @@ - (void)layoutSubviews
// Work out the cancel button frame
CGRect frame = CGRectZero;
frame.size.height = 44.0f;
frame.size.width = MIN(self.frame.size.width / 3.0, self.cancelTextButton.frame.size.width);
frame.size.width = _showOnlyIcons ? 44.0f : MIN(self.frame.size.width / 3.0, self.cancelTextButton.frame.size.width);

//If normal layout, place on the left side, else place on the right
if (self.reverseContentLayout == NO) {
Expand All @@ -187,28 +187,28 @@ - (void)layoutSubviews
else {
frame.origin.x = boundsSize.width - (frame.size.width + insetPadding);
}
self.cancelTextButton.frame = frame;
(_showOnlyIcons ? self.cancelIconButton : self.cancelTextButton).frame = frame;

// Work out the Done button frame
frame.size.width = MIN(self.frame.size.width / 3.0, self.doneTextButton.frame.size.width);
frame.size.width = _showOnlyIcons ? 44.0f : MIN(self.frame.size.width / 3.0, self.doneTextButton.frame.size.width);

if (self.reverseContentLayout == NO) {
frame.origin.x = boundsSize.width - (frame.size.width + insetPadding);
}
else {
frame.origin.x = insetPadding;
}
self.doneTextButton.frame = frame;
(_showOnlyIcons ? self.doneIconButton : self.doneTextButton).frame = frame;

// Work out the frame between the two buttons where we can layout our action buttons
CGFloat x = self.reverseContentLayout ? CGRectGetMaxX(self.doneTextButton.frame) : CGRectGetMaxX(self.cancelTextButton.frame);
CGFloat x = self.reverseContentLayout ? CGRectGetMaxX((_showOnlyIcons ? self.doneIconButton : self.doneTextButton).frame) : CGRectGetMaxX((_showOnlyIcons ? self.cancelIconButton : self.cancelTextButton).frame);
CGFloat width = 0.0f;

if (self.reverseContentLayout == NO) {
width = CGRectGetMinX(self.doneTextButton.frame) - CGRectGetMaxX(self.cancelTextButton.frame);
width = CGRectGetMinX((_showOnlyIcons ? self.doneIconButton : self.doneTextButton).frame) - CGRectGetMaxX((_showOnlyIcons ? self.cancelIconButton : self.cancelTextButton).frame);
}
else {
width = CGRectGetMinX(self.cancelTextButton.frame) - CGRectGetMaxX(self.doneTextButton.frame);
width = CGRectGetMinX((_showOnlyIcons ? self.cancelIconButton : self.cancelTextButton).frame) - CGRectGetMaxX((_showOnlyIcons ? self.doneIconButton : self.doneTextButton).frame);
}

CGRect containerRect = CGRectIntegral((CGRect){x,frame.origin.y,width,44.0f});
Expand Down Expand Up @@ -400,6 +400,16 @@ - (CGRect)doneButtonFrame
return self.doneTextButton.frame;
}

- (void)setShowOnlyIcons:(BOOL)showOnlyIcons {
if (_showOnlyIcons == showOnlyIcons)
return;

_showOnlyIcons = showOnlyIcons;
[_doneIconButton sizeToFit];
[_cancelIconButton sizeToFit];
[self setNeedsLayout];
}

- (void)setCancelTextButtonTitle:(NSString *)cancelTextButtonTitle {
_cancelTextButtonTitle = cancelTextButtonTitle;
[_cancelTextButton setTitle:_cancelTextButtonTitle forState:UIControlStateNormal];
Expand Down
10 changes: 10 additions & 0 deletions Swift/CropViewController/CropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,16 @@ open class CropViewController: UIViewController, TOCropViewControllerDelegate {
get { return toCropViewController.cancelButtonTitle }
}

/**
If true, button icons are visible in portairt instead button text.

Default is NO.
*/
public var showOnlyIcons: Bool {
set { toCropViewController.showOnlyIcons = newValue }
get { return toCropViewController.showOnlyIcons }
}

/**
Color for the 'Done' button.
Setting this will override the default color.
Expand Down