1

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

1

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];
}
Jasper Blues
  • 28,258
  • 22
  • 102
  • 185
  • you told me ManiacDev which is excellent, I do appreciate if you tell me more useful websites as I am beginner. – user2211254 Jun 21 '13 at 10:20
  • you know, what I want to do is add layer of information on the CAMERA once a code has detected, this layer contains buttons,tabbar... what do you suggest me to implement this? could you please provide me by sample code for options that suggested me. – user2211254 Jun 21 '13 at 10:23
  • Added the info you wanted. – Jasper Blues Jun 21 '13 at 11:02