在ZBar扫描仪顶部添加叠加层

时间:2012-11-28 20:03:58

标签: ios titanium zbar-sdk titanium-modules zbar

我正在使用ZBar SDK来读取iPhone上的二维码,但是我想在相机/扫描仪视图的底部添加一些文字,这些文字是用户的指导文字。以下是我到目前为止的情况:

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];

以下是完整的课程:

https://gist.github.com/4163761

不幸的是,标签没有显示。 ZBar的文档说为了这个目的使用cameraOverlayView,但它似乎没有用。

另一个注意事项,我正在使用Titanium框架,因此这是额外Titanium类的来源,但我的问题应该是特定于ZBar。

1 个答案:

答案 0 :(得分:6)

你看到cameraOverlayView了吗?将背景颜色设置为红色或其他:cameraOverlayView.backgroundColor = [UIColor redColor];

如果你根本看不到cameraOverlayView,那么你可能需要设置阅读器。 showsZBarControls = NO将禁用默认控件并使用自定义叠加。

如果你看到cameraOverlayView,那么标签可能超出界限。使用原点进行游戏并将其置于适当的位置。

BTW我发现你没有使用ARC,请确保你发布了InstructionLabel!

相关问题