tranvutuan
tranvutuan

Reputation: 6109

add a uibarbutton for ZBarReaderViewController

I am working on ZBarReader and What I am having so far right now is

ZBarReaderViewController *controller = [[ZBarReaderViewController alloc] init];
controller.navigationController.navigationBarHidden = NO;
// Add Edit button to the right and handle click event UIBarButtonItem *manualButton = [[UIBarButtonItem alloc] initWithTitle:@"Manual" style:UIBarButtonItemStyleBordered target:self action:@selector(EditMode:)];
[controller.navigationItem setRightBarButtonItem:manualButton];
controller.readerDelegate = self;
[self presentModalViewController:controller animated:YES];

My question is that can we so such things above : set toolbar visible and add button on it for ZBarReaderViewController.

Upvotes: 2

Views: 1758

Answers (2)

MeganZhou
MeganZhou

Reputation: 344

Besides @Mat answer, should add [self.zReader.view setFrame:[UIScreen mainScreen].bounds]; before self.zReader.cameraOverlayView=[self setOverlayPickerView];

Because, by default, the size of self.zReader is (320, 480).

By the way, if no need compatible iOS6.0, you can just use [AVCaptureDevice]: https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVCaptureDevice_Class/Reference/Reference.html

Upvotes: 0

Mat
Mat

Reputation: 7643

Yes, you have set some property first to your ZBarReaderViewController

 self.zReader.showsCameraControls = NO;
 self.zReader.showsZBarControls=NO;

Then you have to set your custom cameraOverlayView, for example this set a UIToolBar with a left button to dismiss the picker and a UISwitch to control the flashMode:

 self.zReader.cameraOverlayView=[self setOverlayPickerView];

- (UIView *)setOverlayPickerView{
    UIView *v=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [v setBackgroundColor:[UIColor clearColor]];
    UIToolbar *myToolBar = [[UIToolbar alloc] init];
    UIBarButtonItem *backButton=[[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(dismissOverlayView:)];
    UISwitch *sw=[[UISwitch alloc] init];
    [sw setOn:NO];
    UIBarButtonItem *switchButton=[[UIBarButtonItem alloc] initWithCustomView:sw];
    UIBarButtonItem *fixed=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];  
    [sw addTarget:self action:@selector(handleSwitchFlash:) forControlEvents:UIControlEventValueChanged];
    [myToolBar setItems:[NSArray arrayWithObjects:backButton,fixed,switchButton,nil]];
    [myToolBar setBarStyle:UIBarStyleDefault];
    CGRect toolBarFrame;
    toolBarFrame = CGRectMake(0, 436, 320, 44);
    [myToolBar setFrame:toolBarFrame];
    [v addSubview:myToolBar];
    return  v;
}

- (void)dismissOverlayView:(id)sender{ 
    [self dismissModalViewControllerAnimated: YES];
}

Upvotes: 8

Related Questions