Adding the Barcode View to a View
Send Feedback

Glossary Item Box

Topic Overview

Purpose

This topic explains, with a code example how to create a basic instance of the IGBarcodeView™ control and display it on a view.

Required background

The following table lists the prerequisite topic required to understanding this topic.

Topic

Purpose

Adding the IG Framework File

This topic explains how to add the IG framework file to a project.


In this topic


Displaying the IGBarcodeView – Code Example

Description

This code example illustrates the creation of a Code 128 barcode with its frame size set to 300x200.

Preview

Code

To start, the background color of the view controller’s view is set to white.

In Objective-C:

self.view.backgroundColor = [UIColor whiteColor];

In C#:

this.View.BackgroundColor = UIColor.White;

Next, create an instance of the IGBarcodeView with the IGBarcodeTypeCode128 type and has a 300x200 size.

In Objective-C:

CGRect barcodeRect = CGRectMake(0, 0, 300, 200);
IGBarcodeView *barcode = [[IGBarcodeView alloc] initWithFrame:barcodeRect barcodeType:IGBarcodeTypeCode128];

In C#:

RectangleF barcodeRect = new RectangleF(0, 0, 300, 200);
IGBarcodeView barcode = IGBarcodeView.CreateBarcodeFrame(IGBarcodeType.IGBarcodeTypeCode128, barcodeRect);

Set the auto-resizing mask for height, width and all sides of the barcode.

In Objective-C:

barcode.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|
            UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleBottomMargin|
            UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin;

In C#:

barcode.AutoresizingMask = UIViewAutoresizing.FlexibleWidth|UIViewAutoresizing.FlexibleHeight|
                                      UIViewAutoresizing.FlexibleLeftMargin|UIViewAutoresizing.FlexibleBottomMargin|
                                      UIViewAutoresizing.FlexibleRightMargin|UIViewAutoresizing.FlexibleTopMargin;

Set the barcode value to “Getting Started.”

In Objective-C:

[barcode setValue:@"Getting Started"];

In C#:

barcode.SetValue ("Getting Started");

Place the barcode in the center of the view controller’s view.

In Objective-C:

barcode.center = self.view.center;

In C#:

barcode.Center = this.View.Center;

Finally, add the barcode to the view controller’s view.

In Objective-C:

[self.view addSubview:barcode];

In C#:

this.View.Add (barcode);

Related Content

Topics

The following topic provides additional information related to this topic.

Topic

Purpose

This topic provides a conceptual overview of the IGBarcodeView control and its key features.