Latest 1.5.0
Homepage https://github.com/leezhihua/ZBarTool
License MIT
Platforms ios 8.0, requires ARC
Frameworks AVFoundation

使用原生封装扫描二维码、条形码的工具,同时可以生成、识别二维码图片

生成二维码

/**
 生成二维码图片,默认size = 150

 @param content             内容
 @return                    二维码图片
 */
+ (UIImage *)encodeQRCodeImageWithContent:(NSString *)content;

/**
 生成二维码图片,可配置二维码大小

 @param content             内容
 @param size                大小
 @return                    二维码图片
 */
+ (UIImage *)encodeQRCodeImageWithContent:(NSString *)content size:(CGFloat)size;

/**
 生成二维码图片,可配置二维码大小、背景色和主题色

 @param content             内容
 @param size                大小
 @param backgroundColor     二维码背景色
 @param themeColor          二维码主题色
 @return                    二维码图片
 */
+ (UIImage *)encodeQRCodeImageWithContent:(NSString *)content size:(CGFloat)size backgroundColor:(UIColor *)backgroundColor themeColor:(UIColor *)themeColor;

/**
 生成二维码图片,可配置二维码大小、背景色和主题色, 可插入图片

 @param content             内容
 @param size                大小
 @param backgroundColor     二维码背景色
 @param themeColor          二维码主题色
 @param aImage              插入图片
 @param cornerRadius        插入图片圆角,如果不设圆角可传0
 @return                    二维码图片
 */
+ (UIImage *)encodeQRCodeImageWithContent:(NSString *)content size:(CGFloat)size backgroundColor:(UIColor *)backgroundColor themeColor:(UIColor *)themeColor insetImage:(UIImage *)aImage imageCornerRadius:(CGFloat)cornerRadius;

使用例子

UIImage *image = [ZBarTool encodeQRCodeImageWithContent:@"https://www.apple.com" size:300 backgroundColor:[UIColor clearColor] themeColor:[UIColor purpleColor] insetImage:[UIImage imageNamed:@"beautiful"] imageCornerRadius:50];
self.imageView.image = image;

识别二维码

NSString *content = [ZBarTool decodeQRCodeImage:self.imageView.image];
self.label.text = content;

扫描

ZBarTool *tool = [ZBarTool barTool];  
[tool startScanBarWithScanRect:self.scanRect scanType:ZBarScanTypeAll layerView:self.view];
tool.scanBarGetObject = ^(NSString * _Nonnull objects) {
  NSLog(@"%@", objects);
};

内部有封装好的扫描视图,可以直接使用

ZBarSacnView *scanView = [[ZBarSacnView alloc] initWithFrame:self.view.bounds scanRect:self.scanRect];
[self.view addSubview:scanView];
[scanView startScanBar];

Latest podspec

{
    "name": "ZBarTool",
    "version": "1.5.0",
    "summary": "u4e8cu7ef4u7801u5de5u5177",
    "description": ""u4f7fu7528u539fu751fu5c01u88c5u626bu63cfu4e8cu7ef4u7801u3001u6761u5f62u7801u7684u5de5u5177uff0cu540cu65f6u53efu4ee5u751fu6210u3001u8bc6u522bu4e8cu7ef4u7801u56feu7247"",
    "homepage": "https://github.com/leezhihua/ZBarTool",
    "license": "MIT",
    "authors": "lzh",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/leezhihua/ZBarTool.git",
        "tag": "1.5.0"
    },
    "source_files": [
        "ZBarTool",
        "ZBarTool/ZBar/*.{h,m}"
    ],
    "resources": [
        "ZBarTool/ZBar/[email protected]",
        "ZBarTool/ZBar/[email protected]"
    ],
    "frameworks": "AVFoundation",
    "requires_arc": true
}

Pin It on Pinterest

Share This