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.
ios swift
add a comment |
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.
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 |
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.
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
5,17811027
5,17811027
asked Nov 11 at 10:20
Nouf
12011
12011
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
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
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 |
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.
add a comment |
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
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 |
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
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 |
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
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
1,105215
1,105215
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 |
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.
add a comment |
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.
add a comment |
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.
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