diff --git a/Demo/SwiftyCropDemo/SwiftyCropDemoApp.swift b/Demo/SwiftyCropDemo/SwiftyCropDemoApp.swift index fb7e2bb..0725a28 100644 --- a/Demo/SwiftyCropDemo/SwiftyCropDemoApp.swift +++ b/Demo/SwiftyCropDemo/SwiftyCropDemoApp.swift @@ -1,10 +1,3 @@ -// -// SwiftyCropDemoApp.swift -// SwiftyCropDemo -// -// Created by Leonid Zolotarev on 1/23/24. -// - import SwiftUI @main diff --git a/Demo/SwiftyCropDemo/UIElements/LongText.swift b/Demo/SwiftyCropDemo/UIElements/LongText.swift index 77e211a..84fc5a2 100644 --- a/Demo/SwiftyCropDemo/UIElements/LongText.swift +++ b/Demo/SwiftyCropDemo/UIElements/LongText.swift @@ -1,10 +1,3 @@ -// -// LongText.swift -// SwiftyCropDemo -// -// Created by Leonid Zolotarev on 1/24/24. -// - import SwiftUI struct LongText: View { diff --git a/README.md b/README.md index 481382b..26247d1 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,7 @@ You can also configure `SwiftyCropView` by passing a `SwiftyCropConfiguration`. | `rotateImage` | `Bool`: Whether the image can be rotated when cropping using pinch gestures. Defaults to `false`. | | `zoomSensitivity` | `CGFloat`: Zoom sensitivity when cropping. Increase to make zoom faster / less sensitive. Defaults to `1.0`. | | `rectAspectRatio` | `CGFloat`: The aspect ratio to use when a rectangular mask shape is used. Defaults to `4:3`. | +| `customTexts` | `Texts`: Defines custom texts for the buttons and instructions. Defaults to `nil` using localized strings from resources. | Create a configuration like this: ```swift @@ -164,7 +165,12 @@ let configuration = SwiftyCropConfiguration( cropImageCircular: false, rotateImage: true, zoomSensitivity = 1.0, - rectAspectRatio = 4/3 + rectAspectRatio = 4/3, + customTexts = SwiftyCropConfiguration.Texts( + cancelButtonText: "Cancel", + interactionInstructionsText: "Custom instruction text", + saveButtonText: "Save" + ) ) ``` and use it like this: @@ -201,7 +207,7 @@ Thanks to [@yhirano](https://github.com/yhirano) for adding the japanese localiz ## ✍️ Author -Benedikt Betz & CHECK24 +Benedikt Betz ## 📃 License diff --git a/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift b/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift index 587e767..3683735 100644 --- a/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift +++ b/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift @@ -8,6 +8,23 @@ public struct SwiftyCropConfiguration { public let rotateImage: Bool public let zoomSensitivity: CGFloat public let rectAspectRatio: CGFloat + public let customTexts: Texts? + + public struct Texts { + public init( + cancelButtonText: String, + interactionInstructionsText: String, + saveButtonText: String + ) { + self.cancelButtonText = cancelButtonText + self.interactionInstructionsText = interactionInstructionsText + self.saveButtonText = saveButtonText + } + + public let cancelButtonText: String + public let interactionInstructionsText: String + public let saveButtonText: String + } /// Creates a new instance of `SwiftyCropConfiguration`. /// @@ -23,13 +40,16 @@ public struct SwiftyCropConfiguration { /// - zoomSensitivity: Sensitivity when zooming. Default is `1.0`. Decrease to increase sensitivity. /// /// - rectAspectRatio: The aspect ratio to use when a `.rectangle` mask shape is used. Defaults to `4:3`. + /// + /// - customTexts: `Texts` object when using custom texts for the cropping view. public init( maxMagnificationScale: CGFloat = 4.0, maskRadius: CGFloat = 130, cropImageCircular: Bool = false, rotateImage: Bool = false, zoomSensitivity: CGFloat = 1, - rectAspectRatio: CGFloat = 4/3 + rectAspectRatio: CGFloat = 4/3, + customTexts: Texts? = nil ) { self.maxMagnificationScale = maxMagnificationScale self.maskRadius = maskRadius @@ -37,5 +57,6 @@ public struct SwiftyCropConfiguration { self.rotateImage = rotateImage self.zoomSensitivity = zoomSensitivity self.rectAspectRatio = rectAspectRatio + self.customTexts = customTexts } } diff --git a/Sources/SwiftyCrop/View/CropView.swift b/Sources/SwiftyCrop/View/CropView.swift index c2349f6..a2dd0f1 100644 --- a/Sources/SwiftyCrop/View/CropView.swift +++ b/Sources/SwiftyCrop/View/CropView.swift @@ -73,7 +73,10 @@ struct CropView: View { } VStack { - Text("interaction_instructions", tableName: localizableTableName, bundle: .module) + Text( + configuration.customTexts?.interactionInstructionsText ?? + NSLocalizedString("interaction_instructions", tableName: localizableTableName, bundle: .module, comment: "") + ) .font(.system(size: 16, weight: .regular)) .foregroundColor(.white) .padding(.top, 30) @@ -116,7 +119,10 @@ struct CropView: View { Button { dismiss() } label: { - Text("cancel_button", tableName: localizableTableName, bundle: .module) + Text( + configuration.customTexts?.cancelButtonText ?? + NSLocalizedString("cancel_button", tableName: localizableTableName, bundle: .module, comment: "") + ) } .foregroundColor(.white) @@ -126,7 +132,10 @@ struct CropView: View { onComplete(cropImage()) dismiss() } label: { - Text("save_button", tableName: localizableTableName, bundle: .module) + Text( + configuration.customTexts?.saveButtonText ?? + NSLocalizedString("save_button", tableName: localizableTableName, bundle: .module, comment: "") + ) } .foregroundColor(.white) } diff --git a/Tests/SwiftyCropTests/SwiftyCropTests.swift b/Tests/SwiftyCropTests/SwiftyCropTests.swift index a9c7f41..c7996d0 100644 --- a/Tests/SwiftyCropTests/SwiftyCropTests.swift +++ b/Tests/SwiftyCropTests/SwiftyCropTests.swift @@ -7,12 +7,20 @@ final class SwiftyCropTests: XCTestCase { maxMagnificationScale: 1.0, maskRadius: 1.0, cropImageCircular: true, - rectAspectRatio: 4/3 + rectAspectRatio: 4/3, + customTexts: SwiftyCropConfiguration.Texts( + cancelButtonText: "Test 1", + interactionInstructionsText: "Test 2", + saveButtonText: "Test 3" + ) ) XCTAssertEqual(configuration.maxMagnificationScale, 1.0) XCTAssertEqual(configuration.maskRadius, 1.0) XCTAssertEqual(configuration.cropImageCircular, true) XCTAssertEqual(configuration.rectAspectRatio, 4/3) + XCTAssertEqual(configuration.customTexts?.cancelButtonText, "Test 1") + XCTAssertEqual(configuration.customTexts?.interactionInstructionsText, "Test 2") + XCTAssertEqual(configuration.customTexts?.saveButtonText, "Test 3") } }