从 iOS 应用程序中生成条码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5759073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:41:26  来源:igfitidea点击:

Barcode Generation from within iOS App

iosiphoneipadbarcode

提问by Raymond

I want to take a numerical string and generate a simple barcode that can be read by any scanner.

我想获取一个数字字符串并生成一个可以被任何扫描仪读取的简单条形码。

I can already use the camera and read a barcode but now I would like to generate a barcode.

我已经可以使用相机并读取条码,但现在我想生成条码。

Does anyone know of an sdk that will allow me to do this, resources or code snipets?

有谁知道允许我执行此操作的 sdk、资源或代码片段?

Thank you

谢谢

回答by Jano

The only free library to do this is Cocoa-Touch-Barcodes, which is a fork of cocoabarcodes. If you are considering commercial libraries, there is one called iPhone Barcode Generator.

唯一可以做到这一点的免费库是Cocoa-Touch- Barcodes,它是cocoabarcodes 的一个分支。如果您正在考虑商业图书馆,有一种叫做iPhone Barcode Generator

updateCheck this objective-c port of ZXing: https://github.com/TheLevelUp/ZXingObjC

更新检查ZXing的这个objective-c端口:https: //github.com/TheLevelUp/ZXingObjC

回答by Marc van Nuffel

Include : #import "NKDBarcodeFramework.h"in your Header File and put these lines below in your init function.

包括 :#import "NKDBarcodeFramework.h"在您的头文件中,并将这些行放在您的 init 函数中。

barcode = [NKDExtendedCode39Barcode alloc];
barcode = [barcode initWithContent:@"1234567890123" printsCaption:0];

[barcode calculateWidth];
NSLog(@"%@",[barcode description]);

theImage = [UIImage imageFromBarcode:barcode];
subview = [[UIImageView alloc]initWithFrame:TTScreenBounds()];
[subview setImage:theImage]; 
[self addSubview:subview];

self.frame = self.bounds;

have fun :-)

玩得开心 :-)

回答by Durai Amuthan.H

There are so many barcode types

条形码种类太多了

  • One D
  • Two D
  • Three D
  • 一D
  • 两个 D
  • 三D

Each barcode type has so many subtypes and each has its own purpose.

每种条码类型都有很多子类型,每种都有自己的用途。

I explain how to generate one of the One D barcode type code 39

我解释如何生成一维条码类型代码 39 之一

here i explain how to generate that barcode using Custom font

在这里我解释如何使用自定义字体生成该条码

Steps:

脚步:

1)Download the custom font from here

1)从这里下载自定义字体

2)Attach the file FRE3OF9X.ttf from the downloaded zip

2)从下载的zip中附加文件FRE3OF9X.ttf

3)add the key Fonts provided by applicationin info.plist and in item 0give FRE3OF9X.ttfas value

3)在 info.plist 中添加应用程序提供的 key Fonts,在item 0 中FRE3OF9X.ttf作为值

4)Try the below code snippet

4)试试下面的代码片段

UIFont *fntCode39=[UIFont fontWithName:@"Free3of9Extended" size:30.0];

UILabel *lblBarCodeTest=[[UILabel alloc]initWithFrame:CGRectMake(0,100,768,30)];

[lblBarCodeTest setBackgroundColor:[UIColor lightGrayColor]];

[lblBarCodeTest setTextAlignment:NSTextAlignmentCenter];

[lblBarCodeTest setFont:fntCode39];

[lblBarCodeTest setText:@"*BarCode3Of9_AKA_Code39-ItsA1DBarcode*"];

[self.view addSubview:lblBarCodeTest];

Result:

结果:

Barcode

条码

回答by Andrew Romanov

You can use CoreImage to generate Barcode images. CoreImage contains 4 filters to generate different barcodes: CICode128BarcodeGenerator, CIQRCodeGenerator, CIPDF417BarcodeGenerator, CIAztecCodeGenerator.

您可以使用 CoreImage 生成条码图像。CoreImage 包含 4 个过滤器来生成不同的条码:CICode128BarcodeGeneratorCIQRCodeGeneratorCIPDF417BarcodeGeneratorCIAztecCodeGenerator

回答by Patrick Lin

I've created a simple class for generating Code 39 Barcode, only one .h and one .m needed to add to your project, and with one line of code it generates the UIImage with code 39 encoded data for you, like this:

我创建了一个用于生成 Code 39 条码的简单类,只需要将一个 .h 和一个 .m 添加到您的项目中,并使用一行代码为您生成带有代码 39 编码数据的 UIImage,如下所示:

UIImage *code39Image = [Code39 code39ImageFromString:@"HELLO CODE39" Width:barcode_width Height:barcode_height];

Here's the link to the project on github: [https://github.com/bclin087/Simple-Code39-generator-for-iOS.git]

这是 github 上项目的链接:[ https://github.com/bclin087/Simple-Code39-generator-for-iOS.git]