Getting Started with Xamarin.iOS SfBarcode

2 Mar 20223 minutes to read

Create your first Barcode in Xamarin.iOS

This section explains how to configure a Barcode for iOS application by using Xamarin.iOS. To get started with the Essential Barcode, refer to the following steps and in result, you get the output on iOS devices as follows.

Xamarin.iOS SfBarcode Getting Started
QR Barcode output

Configure the Barcode control

The following steps explain you how to create and configure a Barcode.

  1. Add reference to the SfBarcode in view controller as follows.

After installing Essential Studio for Xamarin, you can find all the required assemblies in the installation folders, typically: {Syncfusion Installed location}\Essential Studio{version number}\lib
You have to add the following assembly reference to the iOS unified project ios-unified \ Syncfusion.SfBarcode.iOS.dll

NOTE

Assemblies are available in unzipped package location in Mac.

2.Create an instance of SfBarcode in view controller and add it as sub view in viewDidLoad override method.

  • C#
  • public override void ViewDidLoad ()
            {
                base.ViewDidLoad ();            
                SFBarcode barcode = new SFBarcode ();
                this.View.AddSubview (barcode);
            }

    3.Then you can assign the text that you want to encode.

  • C#
  • barcode.Text  =   (NSString)"www.wikipedia.org";

    4.Specify the required symbology to encode the given text. By default, the given text is encoded by using the Code39 symbology.

  • C#
  • barcode.Symbology  =  SFBarcodeSymbolType.SFBarcodeSymbolTypeQRCode;

    5.To customize the Barcode, initialize the settings of the corresponding Barcode symbology.

  • C#
  • SFQRBarcodeSettings settings  =  new SFQRBarcodeSettings  ();       
        settings.XDimension  =  6;      
        barcode.SymbologySettings  =  settings;

    6.Finally, the Barcode is generated as displayed in the screenshot by using the following code example.

  • C#
  • public override void ViewDidLoad ()
            {
                base.ViewDidLoad ();
                SFBarcode barcode = new SFBarcode ();
                barcode.Text  =   (NSString)"www.wikipedia.org";
                barcode.Symbology  = SFBarcodeSymbolType.SFBarcodeSymbolTypeQRCode;    
                SFQRBarcodeSettings settings  = new SFQRBarcodeSettings  ();       
                settings.XDimension  =  6;      
                barcode.SymbologySettings  =  settings;
                this.View.AddSubview (barcode);
            }

    Xamarin.iOS SfBarcode Configuration
    Final output of iOS getting started application