2

I want to know if it is possible when using Zbar barcode scanning within an iPhone/iOS app to add some sort or crosshairs or other visual indicator to the screen to assist users in aiming their camera onto a QR code?

user229044
  • 232,980
  • 40
  • 330
  • 338
gonzobrains
  • 7,856
  • 14
  • 81
  • 132

2 Answers2

2

That is best accomplished with a transparent PNG. Just import it to your project and then create a new UIImageView that you give to the reader.

I did this to add a logo:

// Create the reader
self.reader = [ZBarReaderViewController new];
self.reader.readerDelegate = self;

// Create image for adding a logo :)
UIImage *image = [UIImage imageNamed:@"scan_logo.png"];
UIImageView *imageLogo = [[UIImageView alloc] initWithImage:image];
imageLogo.frame = CGRectMake(0, 0, image.size.width, image.size.height);

// Configure reader
self.reader.cameraOverlayView = imageLogo;

To get the image in the center just change the frame positioning from:

imageLogo.frame = CGRectMake(0, 0, image.size.width, image.size.height);

To something like:

imageLogo.center = CGRectMake(320/2, 460/2, image.size.width, image.size.height);
JeroenEijkhof
  • 2,232
  • 2
  • 25
  • 39
  • Thanks, Jeroen. Is there any way to view this in the simulator? – gonzobrains Jun 07 '11 at 04:06
  • Sorry for the late response. No unfortunately not since your computer doesn't have a camera, it will simply give you the option of choosing a picture to scan. Simply save a barcode to your iPhone/iPad simulators picture library and it will appear when you test. Also if the answer I gave was correct please consider marking it as the correct answer. – JeroenEijkhof Jun 09 '11 at 06:52
0

FWIW what I did in my app is to extend the ZBarReaderViewController class, set my new class as the ZBarReaderDelegate also, and then put JeroenEijkhof's code into my init override:

- (id) init
{
    self = [super init];
    if( self ) {
        self.readerDelegate = self;
        UIImage *image = [UIImage imageNamed:...
        ...
    }
    return self;
}

This gave me the ability to control other aspects of the view, such as customizing the navigation controller on viewDidLoad and viewWillAppear since I was implementing the camera view in a NavigationController view stack and wanted the ability to add the titlebar, toolbar, etc. instead of presenting it modally, as the zbar docs demonstrate.

cleverbit
  • 5,514
  • 5
  • 28
  • 38