user2211254
user2211254

Reputation: 31

how to make a view not programmatically as cameraoverlay view

I need to create a cameraoverlay view(to add on ZBar sdk reader), my question is how can I create all objects I need not programmatically. right now I create all objects programmatically and then add them to myView, and use myView as cameraoverlay view.

[self.myView addSubview: myImage];
[self.myView addSubview: self.mylabel];
[self.myView addSubview: myButton];

reader.cameraOverlayView=self.myView;

I tried to add another control view and added a view to it then made a tabbar and tried this code which doesn't work:

TestViewController *test=[[TestViewController alloc]init];
reader.cameraOverlayView=test.testView;

making objects programmatically is hard for me is this possible to find source code for objects which created in xcode, for example when I create a custom button in xcode can I find source code which has generated for this button and just copy it in my program.

Upvotes: 1

Views: 203

Answers (1)

Jasper Blues
Jasper Blues

Reputation: 28786

There are several approaches that will work

  • Create a custom conainer view in code. Add the zbar view, and any custom views (scanner graphics, etc on top). This is what i recently did.

  • Create a xib-baased view, and include the zbar view in that. See the 'object' component.

  • Load custom views from xibs and add them.

If you have the time, I recommend you invest to learn how to create views programmatically.

This involves:

  • in your view contoller override the loadView method.

  • return a custom sub-class of UIView that contains sub-views. These include the zbar view and your overlays.

  • learn how to use the layoutSubviews method on UIView. Hint set your child view's frame relative to thecparent views bounds.

There are loads of custom components on Github. Check out DCSwitch or CMPoptip, or read up on contributions to ManiacDev.

* As requested - adding subviews after successful scan *

- (void)readerView:(ZBarReaderView*)view didReadSymbols:(ZBarSymbolSet*)symbols fromImage:(UIImage*)image
{
    for (ZBarSymbol* symbol in symbols)
    {
        [self presentScannedOverlay];
        [_scanInProgressOverlay setAnimating:NO];
        [_readerView stop];
        [_delegate didScanPayload:symbol.data];
        break;
    }
}


- (void)presentScannedOverlay
{
    //Be sure to override layoutSubviews, so that you can position the view below, 
    //relative to its parent. . if you already know the size of the parent, just replace
    //CGRectZero with CGRectMake(some values)
    _scannedOverlayView = [MyOverlayView alloc] initWithFrame:CGRectZero]; 
    [self addSubView:scannedOverlayView];
}

Upvotes: 1

Related Questions