Multi Line Labels and an Image with UIStackView












0















I am trying to see if I can easily use a UIStackView to create multi line labels and also display an image.



Here are my current constraints.
enter image description here



When I run it I get the following:



enter image description here



If I remove the imageview then the multi line works. Somehow UIImageView width and height is messing up everything. What am I doing wrong?










share|improve this question

























  • Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.

    – Dare
    Jan 3 at 19:35













  • Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.

    – john doe
    Jan 3 at 19:40






  • 1





    In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.

    – Dare
    Jan 3 at 19:42











  • Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.

    – john doe
    Jan 3 at 19:43
















0















I am trying to see if I can easily use a UIStackView to create multi line labels and also display an image.



Here are my current constraints.
enter image description here



When I run it I get the following:



enter image description here



If I remove the imageview then the multi line works. Somehow UIImageView width and height is messing up everything. What am I doing wrong?










share|improve this question

























  • Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.

    – Dare
    Jan 3 at 19:35













  • Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.

    – john doe
    Jan 3 at 19:40






  • 1





    In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.

    – Dare
    Jan 3 at 19:42











  • Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.

    – john doe
    Jan 3 at 19:43














0












0








0








I am trying to see if I can easily use a UIStackView to create multi line labels and also display an image.



Here are my current constraints.
enter image description here



When I run it I get the following:



enter image description here



If I remove the imageview then the multi line works. Somehow UIImageView width and height is messing up everything. What am I doing wrong?










share|improve this question
















I am trying to see if I can easily use a UIStackView to create multi line labels and also display an image.



Here are my current constraints.
enter image description here



When I run it I get the following:



enter image description here



If I remove the imageview then the multi line works. Somehow UIImageView width and height is messing up everything. What am I doing wrong?







ios uistackview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 19:30









rmaddy

246k27327390




246k27327390










asked Jan 3 at 19:27









john doejohn doe

3,039124398




3,039124398













  • Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.

    – Dare
    Jan 3 at 19:35













  • Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.

    – john doe
    Jan 3 at 19:40






  • 1





    In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.

    – Dare
    Jan 3 at 19:42











  • Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.

    – john doe
    Jan 3 at 19:43



















  • Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.

    – Dare
    Jan 3 at 19:35













  • Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.

    – john doe
    Jan 3 at 19:40






  • 1





    In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.

    – Dare
    Jan 3 at 19:42











  • Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.

    – john doe
    Jan 3 at 19:43

















Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.

– Dare
Jan 3 at 19:35







Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.

– Dare
Jan 3 at 19:35















Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.

– john doe
Jan 3 at 19:40





Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.

– john doe
Jan 3 at 19:40




1




1





In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.

– Dare
Jan 3 at 19:42





In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.

– Dare
Jan 3 at 19:42













Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.

– john doe
Jan 3 at 19:43





Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.

– john doe
Jan 3 at 19:43












2 Answers
2






active

oldest

votes


















1














StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.



PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.






share|improve this answer































    1














    Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.
    Xcode Screenshot



    THis is how it will look like
    Screenshot






    share|improve this answer
























      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',
      autoActivateHeartbeat: false,
      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%2f54028617%2fmulti-line-labels-and-an-image-with-uistackview%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.



      PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.






      share|improve this answer




























        1














        StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.



        PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.






        share|improve this answer


























          1












          1








          1







          StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.



          PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.






          share|improve this answer













          StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.



          PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 19:48









          emrepunemrepun

          1,4662619




          1,4662619

























              1














              Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.
              Xcode Screenshot



              THis is how it will look like
              Screenshot






              share|improve this answer




























                1














                Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.
                Xcode Screenshot



                THis is how it will look like
                Screenshot






                share|improve this answer


























                  1












                  1








                  1







                  Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.
                  Xcode Screenshot



                  THis is how it will look like
                  Screenshot






                  share|improve this answer













                  Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.
                  Xcode Screenshot



                  THis is how it will look like
                  Screenshot







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 3 at 22:15









                  Viren PatelViren Patel

                  3817




                  3817






























                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54028617%2fmulti-line-labels-and-an-image-with-uistackview%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

                      Mossoró

                      Error while reading .h5 file using the rhdf5 package in R

                      Pushsharp Apns notification error: 'InvalidToken'