Not able to reduce UITableCustomCell height in iOS using Swift?












-2















I need to reduce the height of the UITableView custom cell, if their is no data for the optional labels to show. following image would be a great help to understand



enter image description here



I tried assigning constraints constant value to 0 and 20 for the pre/post Instruction's respective top/bottom on the availability of data, it's working perfect when both optional values (pre/post instructions) are available, but in case of missing anyvalue the cell is picking the minimum height see below 👇👇



enter image description here



Altough in heightForRowAt method i'm returning




return UITableViewAutomaticDimension




If any of the optional value (On the yellow label) is missing, I need to manage the exterior space of that label in the cell, Please suggest me a better solution 👍👍










share|improve this question





























    -2















    I need to reduce the height of the UITableView custom cell, if their is no data for the optional labels to show. following image would be a great help to understand



    enter image description here



    I tried assigning constraints constant value to 0 and 20 for the pre/post Instruction's respective top/bottom on the availability of data, it's working perfect when both optional values (pre/post instructions) are available, but in case of missing anyvalue the cell is picking the minimum height see below 👇👇



    enter image description here



    Altough in heightForRowAt method i'm returning




    return UITableViewAutomaticDimension




    If any of the optional value (On the yellow label) is missing, I need to manage the exterior space of that label in the cell, Please suggest me a better solution 👍👍










    share|improve this question



























      -2












      -2








      -2








      I need to reduce the height of the UITableView custom cell, if their is no data for the optional labels to show. following image would be a great help to understand



      enter image description here



      I tried assigning constraints constant value to 0 and 20 for the pre/post Instruction's respective top/bottom on the availability of data, it's working perfect when both optional values (pre/post instructions) are available, but in case of missing anyvalue the cell is picking the minimum height see below 👇👇



      enter image description here



      Altough in heightForRowAt method i'm returning




      return UITableViewAutomaticDimension




      If any of the optional value (On the yellow label) is missing, I need to manage the exterior space of that label in the cell, Please suggest me a better solution 👍👍










      share|improve this question
















      I need to reduce the height of the UITableView custom cell, if their is no data for the optional labels to show. following image would be a great help to understand



      enter image description here



      I tried assigning constraints constant value to 0 and 20 for the pre/post Instruction's respective top/bottom on the availability of data, it's working perfect when both optional values (pre/post instructions) are available, but in case of missing anyvalue the cell is picking the minimum height see below 👇👇



      enter image description here



      Altough in heightForRowAt method i'm returning




      return UITableViewAutomaticDimension




      If any of the optional value (On the yellow label) is missing, I need to manage the exterior space of that label in the cell, Please suggest me a better solution 👍👍







      ios iphone swift uitableview uitableviewautomaticdimension






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 15:15







      Mohit Garg

















      asked Nov 20 '18 at 15:07









      Mohit GargMohit Garg

      165139




      165139
























          1 Answer
          1






          active

          oldest

          votes


















          1














          you can achieve this using a UIStackView.



          Just embbed the Pre Instructions, Ingredient Name and Post Instruction inside a Vertical UIStackView, then add the constrains, 20 from top and bottom, whatever you want trailing and the spacing you want from the left label. And finally add the item spacing you want between the UIStackView items (4 o 8 pts for example).



          Then, what you need to do is just hide the label when it has no content and the UIStackView will do the magic for you, it will handle the spacing when an item is hidden.



          ;)






          share|improve this answer
























          • thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)

            – Mohit Garg
            Nov 21 '18 at 5:39













          • @MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.

            – Esteban Vallejo
            Nov 23 '18 at 15:45











          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%2f53395918%2fnot-able-to-reduce-uitablecustomcell-height-in-ios-using-swift%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









          1














          you can achieve this using a UIStackView.



          Just embbed the Pre Instructions, Ingredient Name and Post Instruction inside a Vertical UIStackView, then add the constrains, 20 from top and bottom, whatever you want trailing and the spacing you want from the left label. And finally add the item spacing you want between the UIStackView items (4 o 8 pts for example).



          Then, what you need to do is just hide the label when it has no content and the UIStackView will do the magic for you, it will handle the spacing when an item is hidden.



          ;)






          share|improve this answer
























          • thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)

            – Mohit Garg
            Nov 21 '18 at 5:39













          • @MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.

            – Esteban Vallejo
            Nov 23 '18 at 15:45
















          1














          you can achieve this using a UIStackView.



          Just embbed the Pre Instructions, Ingredient Name and Post Instruction inside a Vertical UIStackView, then add the constrains, 20 from top and bottom, whatever you want trailing and the spacing you want from the left label. And finally add the item spacing you want between the UIStackView items (4 o 8 pts for example).



          Then, what you need to do is just hide the label when it has no content and the UIStackView will do the magic for you, it will handle the spacing when an item is hidden.



          ;)






          share|improve this answer
























          • thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)

            – Mohit Garg
            Nov 21 '18 at 5:39













          • @MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.

            – Esteban Vallejo
            Nov 23 '18 at 15:45














          1












          1








          1







          you can achieve this using a UIStackView.



          Just embbed the Pre Instructions, Ingredient Name and Post Instruction inside a Vertical UIStackView, then add the constrains, 20 from top and bottom, whatever you want trailing and the spacing you want from the left label. And finally add the item spacing you want between the UIStackView items (4 o 8 pts for example).



          Then, what you need to do is just hide the label when it has no content and the UIStackView will do the magic for you, it will handle the spacing when an item is hidden.



          ;)






          share|improve this answer













          you can achieve this using a UIStackView.



          Just embbed the Pre Instructions, Ingredient Name and Post Instruction inside a Vertical UIStackView, then add the constrains, 20 from top and bottom, whatever you want trailing and the spacing you want from the left label. And finally add the item spacing you want between the UIStackView items (4 o 8 pts for example).



          Then, what you need to do is just hide the label when it has no content and the UIStackView will do the magic for you, it will handle the spacing when an item is hidden.



          ;)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 15:29









          Esteban VallejoEsteban Vallejo

          22629




          22629













          • thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)

            – Mohit Garg
            Nov 21 '18 at 5:39













          • @MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.

            – Esteban Vallejo
            Nov 23 '18 at 15:45



















          • thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)

            – Mohit Garg
            Nov 21 '18 at 5:39













          • @MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.

            – Esteban Vallejo
            Nov 23 '18 at 15:45

















          thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)

          – Mohit Garg
          Nov 21 '18 at 5:39







          thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)

          – Mohit Garg
          Nov 21 '18 at 5:39















          @MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.

          – Esteban Vallejo
          Nov 23 '18 at 15:45





          @MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.

          – Esteban Vallejo
          Nov 23 '18 at 15:45




















          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%2f53395918%2fnot-able-to-reduce-uitablecustomcell-height-in-ios-using-swift%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

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)