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.

enter image description here



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.



enter image description here



Thank you all for your kind and valuable input!
Chris










share|improve this question





















  • 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














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.

enter image description here



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.



enter image description here



Thank you all for your kind and valuable input!
Chris










share|improve this question





















  • 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












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.

enter image description here



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.



enter image description here



Thank you all for your kind and valuable input!
Chris










share|improve this question













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.

enter image description here



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.



enter image description here



Thank you all for your kind and valuable input!
Chris







ios uiviewcontroller storyboard ios-autolayout uicontainerview






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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












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.






share|improve this answer




















  • Thats basically the method! Thanks :)
    – Chris
    Nov 15 at 18:02










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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

























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.






share|improve this answer




















  • Thats basically the method! Thanks :)
    – Chris
    Nov 15 at 18:02














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.






share|improve this answer




















  • Thats basically the method! Thanks :)
    – Chris
    Nov 15 at 18:02












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 at 18:32









DonMag

15.6k2926




15.6k2926











  • 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




Thats basically the method! Thanks :)
– Chris
Nov 15 at 18:02

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20