4

I'm using the ZBar SDK to read QR codes on iPhone, however I want to add some text to the bottom of the camera/scanner view that is instructional text for the user. Here is what I have so far:

UIView *cameraOverlayView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    cameraOverlayView.backgroundColor = [UIColor redColor];

    UILabel *instructionLabel = [[UILabel alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    [instructionLabel setTextColor:[UIColor grayColor]];
    [instructionLabel setBackgroundColor:[UIColor clearColor]];
    [instructionLabel setFont:[UIFont fontWithName: @"Trebuchet MS" size: 24.0f]];
    [instructionLabel setCenter:cameraOverlayView.center];
    [cameraOverlayView addSubview:instructionLabel];

    reader.cameraOverlayView = cameraOverlayView;
    reader.wantsFullScreenLayout = YES;

    [instructionLabel release];
    [cameraOverlayView release];

Here is the full class:

https://gist.github.com/4163761

Unfortunately, the label doesn't show. ZBar's documentation says to use the cameraOverlayView for this purpose, however it doesn't seem to be working.

One other note, I'm using the Titanium framework, so that's where the extra Titanium classes are from, however my question should be specific to ZBar.

Justin
  • 17,670
  • 38
  • 132
  • 201

1 Answers1

6

Do you see the cameraOverlayView at all? set the background color to red or something: cameraOverlayView.backgroundColor = [UIColor redColor];

If you don't see the cameraOverlayView at all, then probably you need to set reader. showsZBarControls = NO which will disable the the default controls and use your custom overlay.

If you do see the cameraOverlayView, then the label is probably outside the bounds. Play around with the origin points and get it into position.

BTW I see you're not using ARC, make sure you release instructionLabel!

ninjaneer
  • 6,951
  • 8
  • 60
  • 104
  • The cameraOverlayView shows red when I set the backgroundColor, so that's a good step.. I still can't figure out how to get the label to show over top of it though, I've updated my question with the latest code. – Justin Nov 29 '12 at 16:01
  • 1
    Do you have any text information? I don't see where you are setting the `instrucitonalLabel.text` property. – ninjaneer Nov 29 '12 at 21:15
  • 1
    I laughed out loud when I saw this... :) You are right, all along I had forgotten to set the text of the label... – Justin Nov 30 '12 at 19:07