objective-cxcodeuilabeluiimagepickercontrollercamera-overlay

adding UIlabel to camera overlay view uiimagepickercontroller Xcode objc


I want to add some UILabels on top of my UIImagePickerController's custom OverlayView but can't seem to get it working.

Here is my code.

-(IBAction)getPhoto:(id)sender{
picker = [[UIImagePickerController alloc] init];

picker.allowsEditing = NO;

picker.sourceType =  UIImagePickerControllerSourceTypeCamera ;
picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;

OverlayView = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,1024)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(OverlayView.frame.size.height/2, OverlayView.frame.size.width/2, 30, 100)];
label.textColor = [UIColor whiteColor];
label.text = @"find Me";
[self.OverlayView addSubview:label];
[self.OverlayView bringSubviewToFront:label];
picker.cameraOverlayView = OverlayView;
CGSize screenSize = [[UIScreen mainScreen] bounds].size;   // 320 x 568

float scale = screenSize.height / screenSize.width*3/4;  // screen height divided by the pickerController height ... or:  568 / ( 320*4/3 )

CGAffineTransform translate=CGAffineTransformMakeTranslation(0,(screenSize.height - screenSize.width*4/3)*0.5);
CGAffineTransform fullScreen=CGAffineTransformMakeScale(scale, scale);
picker.cameraViewTransform =CGAffineTransformConcat(fullScreen, translate);
[self presentViewController: picker animated:YES completion:NULL];

}

the overview shows up and it is full screen but no label any ideas


Solution

  • Your label is just offscreen, check its frame

    You can place it for instance like that, at least it will be visible

    self.overlayView = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(self.overlayView.frame.size.width/2, self.overlayView.frame.size.height/2, 30, 100)];