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

Add option to set Cancel and Done buttons colors on iOS #303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions ios/Classes/FLTImageCropperPlugin.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#import <Flutter/Flutter.h>
#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<FlutterPlugin>
@end
10 changes: 9 additions & 1 deletion ios/Classes/FLTImageCropperPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'package:flutter/widgets.dart';

import 'utils.dart';

///
Expand Down Expand Up @@ -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,
Expand All @@ -258,6 +267,8 @@ class IOSUiSettings {
this.title,
this.doneButtonTitle,
this.cancelButtonTitle,
this.doneButtonColor,
this.cancelButtonColor,
});

Map<String, dynamic> toMap() => {
Expand All @@ -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),
};
}

Expand Down