How to make UITableView height fit its content in Swift
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.
ios swift
add a comment |
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.
ios swift
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
add a comment |
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.
ios swift
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.
ios swift
ios swift
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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
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
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 11 at 18:24
lennartk
2111315
2111315
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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