From 33e84d63ef4bc5d517b7cb4108b65f54c14cdb54 Mon Sep 17 00:00:00 2001 From: MarcinusX Date: Fri, 21 Jan 2022 10:45:13 +0100 Subject: [PATCH] Add option to set Cancel and Done buttons colors on iOS --- ios/Classes/FLTImageCropperPlugin.h | 5 +++++ ios/Classes/FLTImageCropperPlugin.m | 10 +++++++++- lib/src/options.dart | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ios/Classes/FLTImageCropperPlugin.h b/ios/Classes/FLTImageCropperPlugin.h index 0cee3198..36180c2c 100644 --- a/ios/Classes/FLTImageCropperPlugin.h +++ b/ios/Classes/FLTImageCropperPlugin.h @@ -1,4 +1,9 @@ #import +#define UIColorFromRGB(rgbValue) \ +[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ + green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 \ + blue:((float)((rgbValue & 0x0000FF) >> 0))/255.0 \ + alpha:1.0] @interface FLTImageCropperPlugin : NSObject @end diff --git a/ios/Classes/FLTImageCropperPlugin.m b/ios/Classes/FLTImageCropperPlugin.m index 2a27ba4c..a5aa025f 100644 --- a/ios/Classes/FLTImageCropperPlugin.m +++ b/ios/Classes/FLTImageCropperPlugin.m @@ -108,7 +108,9 @@ - (void)setupUiCustomizedOptions:(id)options forViewController:(TOCropViewContro NSString *title = options[@"ios.title"]; NSString *doneButtonTitle = options[@"ios.done_button_title"]; NSString *cancelButtonTitle = options[@"ios.cancel_button_title"]; - + NSNumber *doneButtonColor = options[@"ios.done_button_color"]; + NSNumber *cancelButtonColor = options[@"ios.cancel_button_color"]; + if (minimumAspectRatio && [minimumAspectRatio isKindOfClass:[NSNumber class]]) { controller.minimumAspectRatio = minimumAspectRatio.floatValue; } @@ -157,6 +159,12 @@ - (void)setupUiCustomizedOptions:(id)options forViewController:(TOCropViewContro if (cancelButtonTitle && [cancelButtonTitle isKindOfClass:[NSString class]]) { controller.cancelButtonTitle = cancelButtonTitle; } + if (doneButtonColor && [doneButtonColor isKindOfClass:[NSNumber class]]) { + controller.doneButtonColor = UIColorFromRGB([doneButtonColor intValue]); + } + if (cancelButtonColor && [cancelButtonColor isKindOfClass:[NSNumber class]]) { + controller.cancelButtonColor = UIColorFromRGB([cancelButtonColor intValue]); + } } - (TOCropViewControllerAspectRatioPreset)parseAspectRatioPresetFromName:(NSString*)name { diff --git a/lib/src/options.dart b/lib/src/options.dart index 8d7ea473..05e48ba5 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:flutter/widgets.dart'; + import 'utils.dart'; /// @@ -239,6 +240,14 @@ class IOSUiSettings { /// Setting this will override the Default which is a localized string for "Cancel". final String? cancelButtonTitle; + /// Color for the 'Done' button. + /// Setting this will override the Default which is some sort of yellow. + final Color? doneButtonColor; + + /// Color for the 'Cancel' button. + /// Setting this will override the Default which is some sort of blue. + final Color? cancelButtonColor; + const IOSUiSettings({ this.minimumAspectRatio, this.rectX, @@ -258,6 +267,8 @@ class IOSUiSettings { this.title, this.doneButtonTitle, this.cancelButtonTitle, + this.doneButtonColor, + this.cancelButtonColor, }); Map toMap() => { @@ -282,6 +293,8 @@ class IOSUiSettings { 'ios.title': this.title, 'ios.done_button_title': this.doneButtonTitle, 'ios.cancel_button_title': this.cancelButtonTitle, + 'ios.done_button_color': int32(this.doneButtonColor?.value), + 'ios.cancel_button_color': int32(this.cancelButtonColor?.value), }; }