Create QR Code with custom logo and color in Swift

Tram Ho

QR Code is used a lot to share content or add new users in apps like Twitter and Snapchat. Starting with iOS 11, users can scan QR codes with the camera app built into iOS. And iOS can also generate QR codes for embedded content.

1. Proceed to create QR code in iOS

Creating QR codes in iOS is easier than ever since the introduction of the CIQRCodeGenerator core image filter. It generates a simple black and white QR code for the given input string. We do the following:

This QR code works, but it doesn’t look very appealing and it probably won’t suit your app design. Hence, it would be really great if we could customize it ourselves to suit our application design.

2. Perform color change of the QR code

The first step in customizing the QR code is to change the colors. We’ll do this in three steps:

  • Invert black and white
  • Cover black to transparent
  • Change color

To make this code easier to use, we will create an extension for CIImage .

QR codes usually link to a URL. Therefore, you should also create an extension for the URL

Or the QR code can be generated from any String, we add the following method to use in this case:

We proceed to generate a QR code from the URL with the following blue color:

And this is the result :

3. QR code with custom logo

To make it a truly outstanding QR code, we can add our own custom little logo inside the QR CIImage using a UIImage extension:

Note: When you try to set the width / height of the logo to be small, make sure it’s not too big, otherwise it will make the QR code unreadable.

We proceed to fully implement the code as follows:

And here is the result:

4. Conclusion

Creating QR codes with custom colors and logos will make your app more attractive and beautiful to match your app design. Hopefully, this will help you in coding more efficiently.

So my post here is over. Thank you for watching the article.

Share the news now

Source : Viblo