How to make UITableView height fit its content in Swift










1














I have UITableView and i want the height to fit its content with on extra space as you can see from the images. When i have more than 2 rows, the tableView will look fine but for 1 or 2 rows it will have this extra space at the bottom. I would like to mention that i do want to fix the height of my tableView. 4 rows is my max.



enter image description here



enter image description here



enter image description here










share|improve this question























  • no it is not I put the green so it easy it see the different , I will add another image
    – Nouf
    Nov 11 at 10:56






  • 1




    Try set table view background color to clear
    – Robert Dresler
    Nov 11 at 11:07










  • please explain more!! you want height of cell to be fit or height of tableView ?
    – andesta.erfan
    Nov 11 at 11:13










  • you were correct setting the background color to clear fix the issue
    – Nouf
    Nov 11 at 12:26










  • @Nouf I created answer from my comment. You can confirm.
    – Robert Dresler
    Nov 11 at 12:41















1














I have UITableView and i want the height to fit its content with on extra space as you can see from the images. When i have more than 2 rows, the tableView will look fine but for 1 or 2 rows it will have this extra space at the bottom. I would like to mention that i do want to fix the height of my tableView. 4 rows is my max.



enter image description here



enter image description here



enter image description here










share|improve this question























  • no it is not I put the green so it easy it see the different , I will add another image
    – Nouf
    Nov 11 at 10:56






  • 1




    Try set table view background color to clear
    – Robert Dresler
    Nov 11 at 11:07










  • please explain more!! you want height of cell to be fit or height of tableView ?
    – andesta.erfan
    Nov 11 at 11:13










  • you were correct setting the background color to clear fix the issue
    – Nouf
    Nov 11 at 12:26










  • @Nouf I created answer from my comment. You can confirm.
    – Robert Dresler
    Nov 11 at 12:41













1












1








1







I have UITableView and i want the height to fit its content with on extra space as you can see from the images. When i have more than 2 rows, the tableView will look fine but for 1 or 2 rows it will have this extra space at the bottom. I would like to mention that i do want to fix the height of my tableView. 4 rows is my max.



enter image description here



enter image description here



enter image description here










share|improve this question















I have UITableView and i want the height to fit its content with on extra space as you can see from the images. When i have more than 2 rows, the tableView will look fine but for 1 or 2 rows it will have this extra space at the bottom. I would like to mention that i do want to fix the height of my tableView. 4 rows is my max.



enter image description here



enter image description here



enter image description here







ios swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 11:08









Kamran

6,04211028




6,04211028










asked Nov 11 at 10:20









Nouf

15313




15313











  • no it is not I put the green so it easy it see the different , I will add another image
    – Nouf
    Nov 11 at 10:56






  • 1




    Try set table view background color to clear
    – Robert Dresler
    Nov 11 at 11:07










  • please explain more!! you want height of cell to be fit or height of tableView ?
    – andesta.erfan
    Nov 11 at 11:13










  • you were correct setting the background color to clear fix the issue
    – Nouf
    Nov 11 at 12:26










  • @Nouf I created answer from my comment. You can confirm.
    – Robert Dresler
    Nov 11 at 12:41
















  • no it is not I put the green so it easy it see the different , I will add another image
    – Nouf
    Nov 11 at 10:56






  • 1




    Try set table view background color to clear
    – Robert Dresler
    Nov 11 at 11:07










  • please explain more!! you want height of cell to be fit or height of tableView ?
    – andesta.erfan
    Nov 11 at 11:13










  • you were correct setting the background color to clear fix the issue
    – Nouf
    Nov 11 at 12:26










  • @Nouf I created answer from my comment. You can confirm.
    – Robert Dresler
    Nov 11 at 12:41















no it is not I put the green so it easy it see the different , I will add another image
– Nouf
Nov 11 at 10:56




no it is not I put the green so it easy it see the different , I will add another image
– Nouf
Nov 11 at 10:56




1




1




Try set table view background color to clear
– Robert Dresler
Nov 11 at 11:07




Try set table view background color to clear
– Robert Dresler
Nov 11 at 11:07












please explain more!! you want height of cell to be fit or height of tableView ?
– andesta.erfan
Nov 11 at 11:13




please explain more!! you want height of cell to be fit or height of tableView ?
– andesta.erfan
Nov 11 at 11:13












you were correct setting the background color to clear fix the issue
– Nouf
Nov 11 at 12:26




you were correct setting the background color to clear fix the issue
– Nouf
Nov 11 at 12:26












@Nouf I created answer from my comment. You can confirm.
– Robert Dresler
Nov 11 at 12:41




@Nouf I created answer from my comment. You can confirm.
– Robert Dresler
Nov 11 at 12:41












2 Answers
2






active

oldest

votes


















1














What you think that is row with wrong height is actually just your table view background.



If you change your table view background color to clear it should fix your issue.



You can use:



Code



tableView.backgroundColor = .clear


Storyboard



enter image description here






share|improve this answer




















  • It was the background color I did set it default, but I did not notice that the red line that make clear was missing so the background was white and not clear
    – Nouf
    Nov 11 at 12:43


















0














You can try turning scrolling off



isScrollingEnabled = false



and use it's intrinsicContentSize with autolayout or just it's contentSize to resize the tableView to exactly fit it's content and get updated automatically.






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%2f53247771%2fhow-to-make-uitableview-height-fit-its-content-in-swift%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














    What you think that is row with wrong height is actually just your table view background.



    If you change your table view background color to clear it should fix your issue.



    You can use:



    Code



    tableView.backgroundColor = .clear


    Storyboard



    enter image description here






    share|improve this answer




















    • It was the background color I did set it default, but I did not notice that the red line that make clear was missing so the background was white and not clear
      – Nouf
      Nov 11 at 12:43















    1














    What you think that is row with wrong height is actually just your table view background.



    If you change your table view background color to clear it should fix your issue.



    You can use:



    Code



    tableView.backgroundColor = .clear


    Storyboard



    enter image description here






    share|improve this answer




















    • It was the background color I did set it default, but I did not notice that the red line that make clear was missing so the background was white and not clear
      – Nouf
      Nov 11 at 12:43













    1












    1








    1






    What you think that is row with wrong height is actually just your table view background.



    If you change your table view background color to clear it should fix your issue.



    You can use:



    Code



    tableView.backgroundColor = .clear


    Storyboard



    enter image description here






    share|improve this answer












    What you think that is row with wrong height is actually just your table view background.



    If you change your table view background color to clear it should fix your issue.



    You can use:



    Code



    tableView.backgroundColor = .clear


    Storyboard



    enter image description here







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 11 at 12:37









    Robert Dresler

    3,3891524




    3,3891524











    • It was the background color I did set it default, but I did not notice that the red line that make clear was missing so the background was white and not clear
      – Nouf
      Nov 11 at 12:43
















    • It was the background color I did set it default, but I did not notice that the red line that make clear was missing so the background was white and not clear
      – Nouf
      Nov 11 at 12:43















    It was the background color I did set it default, but I did not notice that the red line that make clear was missing so the background was white and not clear
    – Nouf
    Nov 11 at 12:43




    It was the background color I did set it default, but I did not notice that the red line that make clear was missing so the background was white and not clear
    – Nouf
    Nov 11 at 12:43













    0














    You can try turning scrolling off



    isScrollingEnabled = false



    and use it's intrinsicContentSize with autolayout or just it's contentSize to resize the tableView to exactly fit it's content and get updated automatically.






    share|improve this answer

























      0














      You can try turning scrolling off



      isScrollingEnabled = false



      and use it's intrinsicContentSize with autolayout or just it's contentSize to resize the tableView to exactly fit it's content and get updated automatically.






      share|improve this answer























        0












        0








        0






        You can try turning scrolling off



        isScrollingEnabled = false



        and use it's intrinsicContentSize with autolayout or just it's contentSize to resize the tableView to exactly fit it's content and get updated automatically.






        share|improve this answer












        You can try turning scrolling off



        isScrollingEnabled = false



        and use it's intrinsicContentSize with autolayout or just it's contentSize to resize the tableView to exactly fit it's content and get updated automatically.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 18:24









        lennartk

        2111315




        2111315



























            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%2f53247771%2fhow-to-make-uitableview-height-fit-its-content-in-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

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo