iOS Auto Resizable Container Views
up vote
0
down vote
favorite
I am building an iOS app with multiple screens but I want avoid duplication of code as well as one large storyboard. Ideally I would like to load the various View Controllers based on a selected storyboard in my content view when needed.
The template of the screen (Master/Root View) shall be composed by 3 Views, namely:
View A that acts as a Navigation View,
View B where the various View Controllers should be loaded based on user actions and,
View C, much like a Tab bar or a 3rd View where I can display some
circumstantial information.
Now, of course I could go with a traditional UINavigationController and UITabBar but I need greater control over those views, notably in terms of size (they have minimum heights that are larger than the ones for NavBar and TabBar).
I also need those Views to resize based on the Traits and Class Size to keep filling the entire screen.
I am trying to use container views to doing so, but I can't get them to resize automatically despite having tried a different set of constraints in auto-layout. Putting the 3 views in a stackview does not do the trick either.
Ultimately I would like to be able to work separately on my various Controller Views that will be loaded in View B, using their own storyboards, calling them programmatically in B and having everything automatically resized.
Thank you all for your kind and valuable input!
Chris
ios uiviewcontroller storyboard ios-autolayout uicontainerview
|
show 4 more comments
up vote
0
down vote
favorite
I am building an iOS app with multiple screens but I want avoid duplication of code as well as one large storyboard. Ideally I would like to load the various View Controllers based on a selected storyboard in my content view when needed.
The template of the screen (Master/Root View) shall be composed by 3 Views, namely:
View A that acts as a Navigation View,
View B where the various View Controllers should be loaded based on user actions and,
View C, much like a Tab bar or a 3rd View where I can display some
circumstantial information.
Now, of course I could go with a traditional UINavigationController and UITabBar but I need greater control over those views, notably in terms of size (they have minimum heights that are larger than the ones for NavBar and TabBar).
I also need those Views to resize based on the Traits and Class Size to keep filling the entire screen.
I am trying to use container views to doing so, but I can't get them to resize automatically despite having tried a different set of constraints in auto-layout. Putting the 3 views in a stackview does not do the trick either.
Ultimately I would like to be able to work separately on my various Controller Views that will be loaded in View B, using their own storyboards, calling them programmatically in B and having everything automatically resized.
Thank you all for your kind and valuable input!
Chris
ios uiviewcontroller storyboard ios-autolayout uicontainerview
A good start here would be having a look at writing your own container view controller. This would allow you to keep your content view controllers separated out into separate storyboards as well as having a custom navigation and tab view.
– marcus.ramsden
Nov 10 at 18:07
If you expect, that containers will resize themselves according to the content size - this is not how they work. You should do it manually.
– kelin
Nov 11 at 9:17
@Marcus Thanks. I have already started to look at it.
– Chris
Nov 12 at 12:25
@Kelin, that's indeed what I want. At least that they can resize according to the screen size.
– Chris
Nov 12 at 12:26
@Chris - are you unable to get the container views to change size? Or unable to get the content of the container views to change size?
– DonMag
Nov 12 at 13:40
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am building an iOS app with multiple screens but I want avoid duplication of code as well as one large storyboard. Ideally I would like to load the various View Controllers based on a selected storyboard in my content view when needed.
The template of the screen (Master/Root View) shall be composed by 3 Views, namely:
View A that acts as a Navigation View,
View B where the various View Controllers should be loaded based on user actions and,
View C, much like a Tab bar or a 3rd View where I can display some
circumstantial information.
Now, of course I could go with a traditional UINavigationController and UITabBar but I need greater control over those views, notably in terms of size (they have minimum heights that are larger than the ones for NavBar and TabBar).
I also need those Views to resize based on the Traits and Class Size to keep filling the entire screen.
I am trying to use container views to doing so, but I can't get them to resize automatically despite having tried a different set of constraints in auto-layout. Putting the 3 views in a stackview does not do the trick either.
Ultimately I would like to be able to work separately on my various Controller Views that will be loaded in View B, using their own storyboards, calling them programmatically in B and having everything automatically resized.
Thank you all for your kind and valuable input!
Chris
ios uiviewcontroller storyboard ios-autolayout uicontainerview
I am building an iOS app with multiple screens but I want avoid duplication of code as well as one large storyboard. Ideally I would like to load the various View Controllers based on a selected storyboard in my content view when needed.
The template of the screen (Master/Root View) shall be composed by 3 Views, namely:
View A that acts as a Navigation View,
View B where the various View Controllers should be loaded based on user actions and,
View C, much like a Tab bar or a 3rd View where I can display some
circumstantial information.
Now, of course I could go with a traditional UINavigationController and UITabBar but I need greater control over those views, notably in terms of size (they have minimum heights that are larger than the ones for NavBar and TabBar).
I also need those Views to resize based on the Traits and Class Size to keep filling the entire screen.
I am trying to use container views to doing so, but I can't get them to resize automatically despite having tried a different set of constraints in auto-layout. Putting the 3 views in a stackview does not do the trick either.
Ultimately I would like to be able to work separately on my various Controller Views that will be loaded in View B, using their own storyboards, calling them programmatically in B and having everything automatically resized.
Thank you all for your kind and valuable input!
Chris
ios uiviewcontroller storyboard ios-autolayout uicontainerview
ios uiviewcontroller storyboard ios-autolayout uicontainerview
asked Nov 10 at 16:45
Chris
266
266
A good start here would be having a look at writing your own container view controller. This would allow you to keep your content view controllers separated out into separate storyboards as well as having a custom navigation and tab view.
– marcus.ramsden
Nov 10 at 18:07
If you expect, that containers will resize themselves according to the content size - this is not how they work. You should do it manually.
– kelin
Nov 11 at 9:17
@Marcus Thanks. I have already started to look at it.
– Chris
Nov 12 at 12:25
@Kelin, that's indeed what I want. At least that they can resize according to the screen size.
– Chris
Nov 12 at 12:26
@Chris - are you unable to get the container views to change size? Or unable to get the content of the container views to change size?
– DonMag
Nov 12 at 13:40
|
show 4 more comments
A good start here would be having a look at writing your own container view controller. This would allow you to keep your content view controllers separated out into separate storyboards as well as having a custom navigation and tab view.
– marcus.ramsden
Nov 10 at 18:07
If you expect, that containers will resize themselves according to the content size - this is not how they work. You should do it manually.
– kelin
Nov 11 at 9:17
@Marcus Thanks. I have already started to look at it.
– Chris
Nov 12 at 12:25
@Kelin, that's indeed what I want. At least that they can resize according to the screen size.
– Chris
Nov 12 at 12:26
@Chris - are you unable to get the container views to change size? Or unable to get the content of the container views to change size?
– DonMag
Nov 12 at 13:40
A good start here would be having a look at writing your own container view controller. This would allow you to keep your content view controllers separated out into separate storyboards as well as having a custom navigation and tab view.
– marcus.ramsden
Nov 10 at 18:07
A good start here would be having a look at writing your own container view controller. This would allow you to keep your content view controllers separated out into separate storyboards as well as having a custom navigation and tab view.
– marcus.ramsden
Nov 10 at 18:07
If you expect, that containers will resize themselves according to the content size - this is not how they work. You should do it manually.
– kelin
Nov 11 at 9:17
If you expect, that containers will resize themselves according to the content size - this is not how they work. You should do it manually.
– kelin
Nov 11 at 9:17
@Marcus Thanks. I have already started to look at it.
– Chris
Nov 12 at 12:25
@Marcus Thanks. I have already started to look at it.
– Chris
Nov 12 at 12:25
@Kelin, that's indeed what I want. At least that they can resize according to the screen size.
– Chris
Nov 12 at 12:26
@Kelin, that's indeed what I want. At least that they can resize according to the screen size.
– Chris
Nov 12 at 12:26
@Chris - are you unable to get the container views to change size? Or unable to get the content of the container views to change size?
– DonMag
Nov 12 at 13:40
@Chris - are you unable to get the container views to change size? Or unable to get the content of the container views to change size?
– DonMag
Nov 12 at 13:40
|
show 4 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
When using addChildViewController(childVC)
/ addChild(childVC)
(Swift 4.1 / 4.2), followed by myContainerView.addSubview(childVC.view)
you need to either
- add constraints for the added subview
or
- set the frame of the subview and
.autoResizingMask
After that, your newly added subview will layout and resize correctly.
Thats basically the method! Thanks :)
– Chris
Nov 15 at 18:02
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
When using addChildViewController(childVC)
/ addChild(childVC)
(Swift 4.1 / 4.2), followed by myContainerView.addSubview(childVC.view)
you need to either
- add constraints for the added subview
or
- set the frame of the subview and
.autoResizingMask
After that, your newly added subview will layout and resize correctly.
Thats basically the method! Thanks :)
– Chris
Nov 15 at 18:02
add a comment |
up vote
1
down vote
accepted
When using addChildViewController(childVC)
/ addChild(childVC)
(Swift 4.1 / 4.2), followed by myContainerView.addSubview(childVC.view)
you need to either
- add constraints for the added subview
or
- set the frame of the subview and
.autoResizingMask
After that, your newly added subview will layout and resize correctly.
Thats basically the method! Thanks :)
– Chris
Nov 15 at 18:02
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
When using addChildViewController(childVC)
/ addChild(childVC)
(Swift 4.1 / 4.2), followed by myContainerView.addSubview(childVC.view)
you need to either
- add constraints for the added subview
or
- set the frame of the subview and
.autoResizingMask
After that, your newly added subview will layout and resize correctly.
When using addChildViewController(childVC)
/ addChild(childVC)
(Swift 4.1 / 4.2), followed by myContainerView.addSubview(childVC.view)
you need to either
- add constraints for the added subview
or
- set the frame of the subview and
.autoResizingMask
After that, your newly added subview will layout and resize correctly.
answered Nov 13 at 18:32
DonMag
15.6k2926
15.6k2926
Thats basically the method! Thanks :)
– Chris
Nov 15 at 18:02
add a comment |
Thats basically the method! Thanks :)
– Chris
Nov 15 at 18:02
Thats basically the method! Thanks :)
– Chris
Nov 15 at 18:02
Thats basically the method! Thanks :)
– Chris
Nov 15 at 18:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241144%2fios-auto-resizable-container-views%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
A good start here would be having a look at writing your own container view controller. This would allow you to keep your content view controllers separated out into separate storyboards as well as having a custom navigation and tab view.
– marcus.ramsden
Nov 10 at 18:07
If you expect, that containers will resize themselves according to the content size - this is not how they work. You should do it manually.
– kelin
Nov 11 at 9:17
@Marcus Thanks. I have already started to look at it.
– Chris
Nov 12 at 12:25
@Kelin, that's indeed what I want. At least that they can resize according to the screen size.
– Chris
Nov 12 at 12:26
@Chris - are you unable to get the container views to change size? Or unable to get the content of the container views to change size?
– DonMag
Nov 12 at 13:40