dagronf / QRCode

A quick and beautiful macOS/iOS/tvOS/watchOS QR Code generator/detector library for SwiftUI, Swift and Objective-C.
MIT License
438 stars 57 forks source link

No LogoTemplate #10

Closed mnbh96 closed 1 year ago

mnbh96 commented 1 year ago

I can't add logo to the qrcode

I'm using SwiftUI

"Value of type 'QRCode.Document' has no member 'logoTemplate'"

dagronf commented 1 year ago

Have you got the latest version? LogoTemplate was added in 11.0.0 so please check that you have (at least) this version in your project.

Can you open the demo project in QRCode/Demo/QRCodeView Demo/ and see if you can compile the macOS Logo Image Demo target?

I created a new SwiftUI project, imported QRCode and was able to use the LogoTemplate functionality as expected. Can you give me any more information as to how you're trying to use the library? macOS/iOS/tvOS/watchOS?

import SwiftUI
import QRCode

struct ContentView: View {

   let doc: QRCode.Document = {
      let d = QRCode.Document(utf8String: "Testing https://github.com/dagronf/QRCode/issues/10")
      let path = CGPath(
         rect: CGRect(x: 0.65, y: 0.75, width: 0.35, height: 0.25),
         transform: nil
      )
      let image = NSImage(systemSymbolName: "rectangle.inset.filled.and.person.filled", accessibilityDescription: nil)
      let logoTemplate = QRCode.LogoTemplate(path: path, image: image?.cgImage(forProposedRect: nil, context: nil, hints: nil))
      d.logoTemplate = logoTemplate
      return d
   }()

   var body: some View {
      VStack {
         QRCodeDocumentUIView(document: doc)
      }
      .padding()
   }
}

struct ContentView_Previews: PreviewProvider {
   static var previews: some View {
      ContentView()
   }
}

The SwiftUI preview shows

image

Here's the project I created.

qrcode-logotemplate.zip

dagronf commented 1 year ago

@mnbh96 any luck with this?

mnbh96 commented 1 year ago

Yes it worked.

For some reason Xcode decided to install version 9 instead of the latest version. I have updated the package like you said and now it works. Thank you.

dagronf commented 1 year ago

Brilliant!