本文主要是介绍iOS--二维码(libqrencode、ZBarSDK),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
二维码就是保存一些字符串的信息。
第三方库下载地址:http://download.csdn.net/detail/u010165653/8294135
创建二维码图片:
使用第三方库,libqrencode,
01:导入第三方库,这个库不需要额外的系统类库。
02 :导入头文件 #import"QRCodeGenerator.h"
03:使用方法:
UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50,50,220, 220)];
[self.view addSubview:imageView];
[imageView release];
imageView.image = [QRCodeGenerator qrImageForString:@"要转成二维码的文本" imageSize:imageView.bounds.size.width];
#import <UIKit/UIKit.h>
#import "QRCodeGenerator.h"@interface ViewController : UIViewController@end<span style="color:#b4261a;">
</span>
#import "ViewController.h"@implementation ViewController- (void)viewDidLoad
{[super viewDidLoad];UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 220, 220)];[self.view addSubview:imageView];[imageView release];imageView.image = [QRCodeGenerator qrImageForString:@"要转成二维码的文本" imageSize:imageView.bounds.size.width];
}@end
扫描二维码图片:
AVFoundation.framework
CoreMedia.framework
CoreVideo.framework
QuartzCore.framework
libiconv.dylib
示例代码:
#import <UIKit/UIKit.h>
#import "ZBarSDK.h"
/*导入ZBarSDK文件并引入一下框架AVFoundation.frameworkCoreMedia.frameworkCoreVideo.frameworkQuartzCore.frameworklibiconv.dylib引入头文件#import “ZBarSDK.h” 即可使用*/@interface ViewController : UIViewController<UINavigationControllerDelegate,UIImagePickerControllerDelegate>@end
#import "ViewController.h"@implementation ViewController- (void)viewDidLoad
{[super viewDidLoad];UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];button.frame = CGRectMake(50, 10, 100, 40);[self.view addSubview:button];[button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];}- (void)buttonClick{ZBarReaderController* zbarController = [[ZBarReaderController alloc] init];zbarController.delegate = self;[self presentModalViewController:zbarController animated:YES];
}- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];ZBarSymbol *symbol = nil;for(symbol in results)break;//最后得到的结果NSLog(@"%@",symbol.data);[picker dismissModalViewControllerAnimated:YES];
}- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{[picker dismissModalViewControllerAnimated:YES];
}@end
这篇关于iOS--二维码(libqrencode、ZBarSDK)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!