0
votes

I am planning to show a small settings menu which has few UISegmentControls and sliders. I don't want to show it full screen, just show it as a subview in my view controller. One way would be to define it as a subclass of UIView altogether but then all designing would have to be done in xib file rather than Storyboard. My questions:

  1. What is the right approach here - UIViewController, UIView, or any of the two?

  2. If we take UIViewController route, how do we design the view in storyboard with a custom size?

1
In storyboard you can imbed a uiviewcontroller in a container view. As far as 1 v 2 that is a personal choice. - agibson007
How do you design view with custom size in Storyboard? - Deepak Sharma
you don't need to do all the designing again just copy viewController's view and paste in XIB :D - Abu Ul Hassan

1 Answers

1
votes

Both the approaches are fine.

But I personally prefer to have UIViewController.

While designing ViewController in Storyboard, I make main view's background color to clear(or sometimes black color with alpha between 0 to 0.5); Now I add other subview inside main view with whatever size that i want.

Now while presenting given view controller, make sure that you are using .overCurrentContext for modalPresentationStyle.

Use code as

myVC?.modalPresentationStyle = .overCurrentContext;
self.present(myVC!, animated: false, completion: nil);

If you use different modalPresentationStyle then, your background will look pure black. But if you use overCurrentContext, then new view controller will be presented above current one, so, if you kept background color as clear then it will be transparent.