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

stroke width an color change dynamically #58

Open ouberghouz opened 3 years ago

ouberghouz commented 3 years ago

can you please add a way to to change the color and the width of the signature dynamically for the same signature.

vladRGaembla commented 1 year ago

@ouberghouz I found a solution. Here is an explanation how "userInterfaceStyle" works and how to prevent it https://stackoverflow.com/questions/58501913/get-image-of-pkdrawing-in-light-mode

As a solution, you can try this

import PencilKit

extension PKDrawing {
  func image(from rect: CGRect, scale: CGFloat, userInterfaceStyle: UIUserInterfaceStyle) -> UIImage {
    let currentTraits = UITraitCollection.current
    UITraitCollection.current = UITraitCollection(userInterfaceStyle: .light) // Here the magic. Try .dark or .light
    let image = self.image(from: rect, scale: scale)
    UITraitCollection.current = currentTraits
    return image
  }
}