diff --git a/Example/Base.lproj/Main.storyboard b/Example/Base.lproj/Main.storyboard index 6521fe01..c0b771b9 100644 --- a/Example/Base.lproj/Main.storyboard +++ b/Example/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -146,7 +146,6 @@ - diff --git a/Example/ViewController.swift b/Example/ViewController.swift index a4c9c163..ad57a777 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -198,8 +198,19 @@ class ViewController: UIViewController, CropViewControllerDelegate { presentWith(backgroundEffect: .light) } - @IBAction func noBackgroundEffect(_ sender: Any) { - presentWith(backgroundEffect: .none) + @IBAction func customColorBackgroundEffect(_ sender: Any) { + guard let image = image else { + return + } + + var config = Mantis.Config() + config.cropViewConfig.backgroundColor = .yellow + let cropViewController = Mantis.cropViewController(image: image, + config: config) + cropViewController.modalPresentationStyle = .fullScreen + cropViewController.delegate = self + present(cropViewController, animated: true) + } typealias CropShapeItem = (type: Mantis.CropShapeType, title: String) diff --git a/Sources/Mantis/CropView/CropView.swift b/Sources/Mantis/CropView/CropView.swift index dc7f1f25..2e1dedaa 100644 --- a/Sources/Mantis/CropView/CropView.swift +++ b/Sources/Mantis/CropView/CropView.swift @@ -106,6 +106,10 @@ class CropView: UIView { self.cropMaskViewManager = cropMaskViewManager super.init(frame: .zero) + + if let color = cropViewConfig.backgroundColor { + self.backgroundColor = color + } viewModel.statusChanged = { [weak self] status in self?.render(by: status) diff --git a/Sources/Mantis/CropViewConfig.swift b/Sources/Mantis/CropViewConfig.swift index 422bd464..f1a2ce36 100644 --- a/Sources/Mantis/CropViewConfig.swift +++ b/Sources/Mantis/CropViewConfig.swift @@ -20,6 +20,15 @@ public struct CropViewConfig { public var cropBorderColor: UIColor = .clear + /** + When backgroundColor is set, cropMaskVisualEffectType is automatically set to custom type + */ + public var backgroundColor: UIColor? { + didSet { + cropMaskVisualEffectType = .custom(color: backgroundColor!) + } + } + public var cropMaskVisualEffectType: CropMaskVisualEffectType = .blurDark public var presetTransformationType: PresetTransformationType = .none diff --git a/Sources/Mantis/Enum.swift b/Sources/Mantis/Enum.swift index 92338354..d9187c54 100644 --- a/Sources/Mantis/Enum.swift +++ b/Sources/Mantis/Enum.swift @@ -41,7 +41,8 @@ public enum CropMaskVisualEffectType { case blurDark case dark case light - case none + case custom(color: UIColor) + case `default` } public enum CropShapeType: Hashable { diff --git a/Sources/Mantis/Mantis.swift b/Sources/Mantis/Mantis.swift index d653518a..0b3917c2 100644 --- a/Sources/Mantis/Mantis.swift +++ b/Sources/Mantis/Mantis.swift @@ -119,6 +119,12 @@ private func buildCropMaskViewManager(with cropViewConfig: CropViewConfig) -> Cr let dimmingView = CropDimmingView(cropShapeType: cropViewConfig.cropShapeType) let visualEffectView = CropMaskVisualEffectView(cropShapeType: cropViewConfig.cropShapeType, effectType: cropViewConfig.cropMaskVisualEffectType) + + if let color = cropViewConfig.backgroundColor { + dimmingView.overLayerFillColor = color.cgColor + visualEffectView.overLayerFillColor = color.cgColor + } + return CropMaskViewManager(dimmingView: dimmingView, visualEffectView: visualEffectView) } diff --git a/Sources/Mantis/MaskBackground/CropDimmingView.swift b/Sources/Mantis/MaskBackground/CropDimmingView.swift index 8c0ec44d..7f732544 100644 --- a/Sources/Mantis/MaskBackground/CropDimmingView.swift +++ b/Sources/Mantis/MaskBackground/CropDimmingView.swift @@ -9,6 +9,8 @@ import UIKit class CropDimmingView: UIView, CropMaskProtocol { + var overLayerFillColor: CGColor = UIColor.black.cgColor + var innerLayer: CALayer? var cropShapeType: CropShapeType = .rect diff --git a/Sources/Mantis/MaskBackground/CropMaskProtocal.swift b/Sources/Mantis/MaskBackground/CropMaskProtocal.swift index fbcbae89..bb48868c 100644 --- a/Sources/Mantis/MaskBackground/CropMaskProtocal.swift +++ b/Sources/Mantis/MaskBackground/CropMaskProtocal.swift @@ -14,6 +14,7 @@ private let initialFrameLength: CGFloat = 1000 protocol CropMaskProtocol: UIView { var cropShapeType: CropShapeType { get set } var innerLayer: CALayer? { get set } + var overLayerFillColor: CGColor { get set } func initialize(cropRatio: CGFloat) func setMask(cropRatio: CGFloat) @@ -123,7 +124,7 @@ extension CropMaskProtocol { let fillLayer = CAShapeLayer() fillLayer.path = path.cgPath fillLayer.fillRule = .evenOdd - fillLayer.fillColor = UIColor.black.cgColor + fillLayer.fillColor = overLayerFillColor fillLayer.opacity = opacity return fillLayer } diff --git a/Sources/Mantis/MaskBackground/CropVisualEffectView.swift b/Sources/Mantis/MaskBackground/CropVisualEffectView.swift index d746e0ce..758c04ae 100644 --- a/Sources/Mantis/MaskBackground/CropVisualEffectView.swift +++ b/Sources/Mantis/MaskBackground/CropVisualEffectView.swift @@ -9,6 +9,8 @@ import UIKit class CropMaskVisualEffectView: UIVisualEffectView, CropMaskProtocol { + var overLayerFillColor: CGColor = UIColor.black.cgColor + var innerLayer: CALayer? var cropShapeType: CropShapeType = .rect @@ -47,7 +49,9 @@ class CropMaskVisualEffectView: UIVisualEffectView, CropMaskProtocol { return (nil, UIColor.black.withAlphaComponent(0.75)) case .light: return (nil, UIColor.black.withAlphaComponent(0.35)) - case .none: + case .custom(let color): + return(nil, color) + case .default: return (nil, .black) } }