How to make UITableView height fit its content in Swift











up vote
1
down vote

favorite












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















up vote
1
down vote

favorite












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













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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

5,28111027




5,28111027










asked Nov 11 at 10:20









Nouf

13011




13011












  • 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

















up vote
1
down vote













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


















up vote
0
down vote













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',
    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








    up vote
    1
    down vote













    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















    up vote
    1
    down vote













    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













    up vote
    1
    down vote










    up vote
    1
    down vote









    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

    1,666318




    1,666318












    • 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












    up vote
    0
    down vote













    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

























      up vote
      0
      down vote













      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























        up vote
        0
        down vote










        up vote
        0
        down vote









        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

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues