iOS中生成指定大小、指定颜色的二维码和条形码方法详解

2020-01-18 19:04:54刘景俊

三.测试

主要


//-----------------------------------二维码、条形码测试--------------------------------------------------
  //条形码
  UIImage *barImage = [Utilities barcodeImageWithContent:@"123456"
codeImageSize:CGSizeMake(300, 90)
red:0                        green:0.4
blue:0.6];
CGRect barImageView_Frame = CGRectMake(self.view.bounds.size.width/2-300/2, 100, 300, 90);
  UIImageView *barImageView = [[UIImageView alloc] initWithFrame:barImageView_Frame];
  barImageView.image = barImage;
  barImageView.backgroundColor = [UIColor clearColor];
  //阴影
  barImageView.layer.shadowOffset = CGSizeMake(-0.5, 0.5);
  barImageView.layer.shadowRadius = 0.5;
  barImageView.layer.shadowColor = [UIColor blackColor].CGColor;
  barImageView.layer.shadowOpacity = 0.2;
[self.view addSubview:barImageView];
//二维码
  UIImage *qrCodeImage = [Utilities qrCodeImageWithContent:@"How are you?"
codeImageSize:200
logo:[UIImage imageNamed:@"logo.png"]
logoFrame:CGRectMake(75, 75, 50, 50)
red:0.0f
green:139/255.0f
blue:139/255.0f];
CGRect qrCodeImageView_Frame = CGRectMake(self.view.bounds.size.width/2-200/2, CGRectGetMaxY(barImageView.frame)+20, 200, 200);
  UIImageView *qrCodeImageView = [[UIImageView alloc] initWithFrame:qrCodeImageView_Frame];
  qrCodeImageView.image = qrCodeImage;
  qrCodeImageView.backgroundColor = [Utilities colorWithHexString:@"#FDF5E6"];// #006400
  //阴影
  qrCodeImageView.layer.shadowOffset = CGSizeMake(0, 0);
  qrCodeImageView.layer.shadowRadius = 5;
  qrCodeImageView.layer.shadowColor = [UIColor blackColor].CGColor;
  qrCodeImageView.layer.shadowOpacity = 0.4;
  [self.view addSubview:qrCodeImageView];

运行结果如下:

iOS,二维码,条形码

运行结果

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持ASPKU!


注:相关教程知识阅读请移步到IOS开发频道。