Add overlay over top of ZBar scanner

2019-05-03 11:23发布

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.

1条回答
迷人小祖宗
2楼-- · 2019-05-03 11:47

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!

查看更多
登录 后发表回答