alankarmisra / SwiftSignatureView

A lightweight, fast and customizable option for capturing fluid, variable-stroke-width signatures within your app.
MIT License
320 stars 93 forks source link

How to avoid dark mode? #50

Open RonnyCoder opened 3 years ago

RonnyCoder commented 3 years ago

I don't want to support dark mode to my App. Issue is at self.signatureView.getCroppedSignature() this return dark mode supported image with white stroke. Need to support only for light theme with black stroke. I tried with setting stroke, background color, tint color but didn't work. Please provide solution.

Thanks in advance.

RonnyCoder commented 3 years ago

Solution: Set self.window?.overrideUserInterfaceStyle = .light Don't add UIUserInterfaceStyle at plist, possibly you may face app rejection. For me setting overrideUserInterfaceStyle to viewcontroller/view not worked.

bludginozzie commented 3 years ago

Why does this signatureView.strokeColor = UIColor.blue work in dark mode but this signatureView.strokeColor = UIColor.black does not?

Like many others here I am trying to get a consistent signature image of black on white across both dark and light modes. Unfortunately after playing with it for several hours I do not think it's possible.

Any assistance would be greatly appreciated.

My full code which does not work, it results in a white stroke on a white background:

override func viewDidLoad() {
        super.viewDidLoad()

        let value = UIInterfaceOrientation.landscapeLeft.rawValue
        UIDevice.current.setValue(value, forKey: "orientation")

        // Force black stroke on white background so the signature image is consistent
        // for both light and dark modes
        signatureView.strokeColor = UIColor.black
        signatureView.backgroundColor = UIColor.white
        signatureView.minimumStrokeWidth = 1
        signatureView.maximumStrokeWidth = 1
        signatureView.strokeAlpha = 1
        if #available(iOS 13.0, *) {
            self.view.window?.overrideUserInterfaceStyle = .light
            if let signaturInnerView = signatureView.subviews.first(where: {$0 is PencilKitSignatureView}) as? PencilKitSignatureView {
                signaturInnerView.strokeColor = UIColor.black
                if let canvasView = signaturInnerView.subviews.first(where: {$0 is PKCanvasView}) {
                    canvasView.backgroundColor = UIColor.white
                }
            }
        }
    }
sddanila commented 2 years ago

Hey! I solved this by always using black, but when it's dark theme, then set the alpha to 0.1.

So instead of using UIColor.white, I used UIColor.black.withAlphaComponent(0.1)

vladRGaembla commented 1 year ago

I found this solution. Hope it saves your day as saved mine: https://github.com/alankarmisra/SwiftSignatureView/issues/58#issuecomment-1315798068