I'm quite surprised. I didn't find anything remotely tackling the issue on SO. I would have imagined that many people may have tried that before me. That must only mean one thing ... It's trivial and I can't make it :(
How do I add constraints to the cameraOverlay ?
I tried this
UIView *overlayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
[overlayView setBackgroundColor:[UIColor redColor]];
[overlayView setAlpha:0.5];
UILabel *Testlabel = [[UILabel alloc] init];
[Testlabel setText:@"Hollllaaaaa in the overlay"];
[overlayView addSubview:Testlabel];
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:overlayView
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:Testlabel
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0];
[overlayView addConstraints:@[widthConstraint]];
[self.picker setCameraOverlayView:overlayView];
But I get the error Unable to simultaneously satisfy constraints
. With just one constraint.
As a note, the picker is part of a view that has constraints and are well defined. I am wondering if the fact that I initwithFrame the overlay view has something to do with autolayout not liking that ... If that the case, how can I simply add a constraint to a blank overlay that would have the same size as the screen ?