I'm a pretty new iOS developer. I love AutoLayout and programmatic UI elements. The use of NSLayoutConstraints just makes so much sense to me, and the place it makes sense to adjust their values is in the code.
Yet almost all info I can find online on creating iOS UI elements uses either XIBs or Storyboards. There's lots of talk about when to use one or the other, including here on SO, but I can't seem to find anything about why someone might want to skip BOTH of them and just do it all in code.
Is there something basic that I'm missing here?
For instance, here's a snippet of my code. Can't I just proceed this way without either XIBs or Storyboards?
UIView *overlayView = [[UIView alloc] initWithFrame:[self getScreenFrameForCurrentOrientation]];
overlayView.opaque = NO;
mHighlightImagePicker.cameraOverlayView = overlayView;
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
float cameraAspectRatio = 4.0 / 3.0;
float imageWidth = floorf(screenSize.width * cameraAspectRatio);
float scale = ceilf(((screenSize.height - 90) / imageWidth) * 100.0) / 100.0;
mHighlightImagePicker.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);
mCameraToolBar=[[UIImageView alloc] init];
mCameraToolBar.image =[UIImage imageNamed:@"review_bottom_bar"];
mCameraToolBar.userInteractionEnabled = YES;
mCameraToolBar.hidden = NO;
[mCameraToolBar setTranslatesAutoresizingMaskIntoConstraints:NO];
[overlayView addConstraint:
[NSLayoutConstraint constraintWithItem:mCameraToolBar
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:overlayView
attribute:NSLayoutAttributeBottom
multiplier:1
constant:-70]];
[overlayView addConstraint:
[NSLayoutConstraint constraintWithItem:mCameraToolBar
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:overlayView
attribute:NSLayoutAttributeLeft
multiplier:1
constant:0]];
[overlayView addConstraint:
[NSLayoutConstraint constraintWithItem:mCameraToolBar
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:overlayView
attribute:NSLayoutAttributeRight
multiplier:1
constant:0]];
[overlayView addConstraint:
[NSLayoutConstraint constraintWithItem:mCameraToolBar
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:overlayView
attribute:NSLayoutAttributeBottom
multiplier:1
constant:0]];
[overlayView addSubview:mCameraToolBar];
loadView
. If you google "loadView tutorial" you'll probably get a bunch of relevant hits.@"H:|[mCameraToolBar]|"
and@"V:[mCameraToolBar(70)]|"
.