简体   繁体   中英

UIViewController Storyboard custom size

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM