TableView calculates wrong height for dynamic width&height label
I've read multiple threads about this but I've found no solution yet.
I'm making a chat-like application
The app has a TableView that has dynamic height cells in it.
A cell consists of a view and a multiline label in it.
If the label has more characters than >250 it gets shortened with an ending "... see more"
Now the problem is that sometimes the label gets cut off.
I played a little with the Line Break
setting of the label, and after changing it to Character Wrap the label shows its full text.
Left picture: Character Wrap
- - - Right picture: Word Wrap
(I need this)
As you see on the right picture, the "Bt... See More" gets cut off..
I realised that if I set the label's width or the view's width to a fixed size then the problem gets solved: So maybe the problem's root is in the bubble view's leading constraint:
Align leading to Superview
Constant: 0
Priority: 1000
Multiplier: 0.25
(This is needed so that the bubble view expands maximum to 75% of the superview)
I made a GitHub repo for this:
https://github.com/krptia/chatBubbleTest
Help please!
Anyone?
swift tableview cell
add a comment |
I've read multiple threads about this but I've found no solution yet.
I'm making a chat-like application
The app has a TableView that has dynamic height cells in it.
A cell consists of a view and a multiline label in it.
If the label has more characters than >250 it gets shortened with an ending "... see more"
Now the problem is that sometimes the label gets cut off.
I played a little with the Line Break
setting of the label, and after changing it to Character Wrap the label shows its full text.
Left picture: Character Wrap
- - - Right picture: Word Wrap
(I need this)
As you see on the right picture, the "Bt... See More" gets cut off..
I realised that if I set the label's width or the view's width to a fixed size then the problem gets solved: So maybe the problem's root is in the bubble view's leading constraint:
Align leading to Superview
Constant: 0
Priority: 1000
Multiplier: 0.25
(This is needed so that the bubble view expands maximum to 75% of the superview)
I made a GitHub repo for this:
https://github.com/krptia/chatBubbleTest
Help please!
Anyone?
swift tableview cell
2
i suggest you to use manual calculation for best performance or you can use hight caching mechanism which give you average performance
– SPatel
Dec 31 '18 at 4:29
1
If you have a solution, post it as an answer, not as part of the question. Or else delete the question so it doesn’t go on sitting here.
– matt
Dec 31 '18 at 16:32
1
What happens if you fix the width? Currently they have variable width. Set it to a fixed width just to try.
– Fogmeister
Dec 31 '18 at 21:40
@Fogmeister I tried that and setting a fixed width to the view or the label fixes the problem.
– Andras Karpati
Jan 1 at 14:52
add a comment |
I've read multiple threads about this but I've found no solution yet.
I'm making a chat-like application
The app has a TableView that has dynamic height cells in it.
A cell consists of a view and a multiline label in it.
If the label has more characters than >250 it gets shortened with an ending "... see more"
Now the problem is that sometimes the label gets cut off.
I played a little with the Line Break
setting of the label, and after changing it to Character Wrap the label shows its full text.
Left picture: Character Wrap
- - - Right picture: Word Wrap
(I need this)
As you see on the right picture, the "Bt... See More" gets cut off..
I realised that if I set the label's width or the view's width to a fixed size then the problem gets solved: So maybe the problem's root is in the bubble view's leading constraint:
Align leading to Superview
Constant: 0
Priority: 1000
Multiplier: 0.25
(This is needed so that the bubble view expands maximum to 75% of the superview)
I made a GitHub repo for this:
https://github.com/krptia/chatBubbleTest
Help please!
Anyone?
swift tableview cell
I've read multiple threads about this but I've found no solution yet.
I'm making a chat-like application
The app has a TableView that has dynamic height cells in it.
A cell consists of a view and a multiline label in it.
If the label has more characters than >250 it gets shortened with an ending "... see more"
Now the problem is that sometimes the label gets cut off.
I played a little with the Line Break
setting of the label, and after changing it to Character Wrap the label shows its full text.
Left picture: Character Wrap
- - - Right picture: Word Wrap
(I need this)
As you see on the right picture, the "Bt... See More" gets cut off..
I realised that if I set the label's width or the view's width to a fixed size then the problem gets solved: So maybe the problem's root is in the bubble view's leading constraint:
Align leading to Superview
Constant: 0
Priority: 1000
Multiplier: 0.25
(This is needed so that the bubble view expands maximum to 75% of the superview)
I made a GitHub repo for this:
https://github.com/krptia/chatBubbleTest
Help please!
Anyone?
swift tableview cell
swift tableview cell
edited Jan 1 at 16:09
Andras Karpati
asked Dec 30 '18 at 22:57
Andras KarpatiAndras Karpati
124117
124117
2
i suggest you to use manual calculation for best performance or you can use hight caching mechanism which give you average performance
– SPatel
Dec 31 '18 at 4:29
1
If you have a solution, post it as an answer, not as part of the question. Or else delete the question so it doesn’t go on sitting here.
– matt
Dec 31 '18 at 16:32
1
What happens if you fix the width? Currently they have variable width. Set it to a fixed width just to try.
– Fogmeister
Dec 31 '18 at 21:40
@Fogmeister I tried that and setting a fixed width to the view or the label fixes the problem.
– Andras Karpati
Jan 1 at 14:52
add a comment |
2
i suggest you to use manual calculation for best performance or you can use hight caching mechanism which give you average performance
– SPatel
Dec 31 '18 at 4:29
1
If you have a solution, post it as an answer, not as part of the question. Or else delete the question so it doesn’t go on sitting here.
– matt
Dec 31 '18 at 16:32
1
What happens if you fix the width? Currently they have variable width. Set it to a fixed width just to try.
– Fogmeister
Dec 31 '18 at 21:40
@Fogmeister I tried that and setting a fixed width to the view or the label fixes the problem.
– Andras Karpati
Jan 1 at 14:52
2
2
i suggest you to use manual calculation for best performance or you can use hight caching mechanism which give you average performance
– SPatel
Dec 31 '18 at 4:29
i suggest you to use manual calculation for best performance or you can use hight caching mechanism which give you average performance
– SPatel
Dec 31 '18 at 4:29
1
1
If you have a solution, post it as an answer, not as part of the question. Or else delete the question so it doesn’t go on sitting here.
– matt
Dec 31 '18 at 16:32
If you have a solution, post it as an answer, not as part of the question. Or else delete the question so it doesn’t go on sitting here.
– matt
Dec 31 '18 at 16:32
1
1
What happens if you fix the width? Currently they have variable width. Set it to a fixed width just to try.
– Fogmeister
Dec 31 '18 at 21:40
What happens if you fix the width? Currently they have variable width. Set it to a fixed width just to try.
– Fogmeister
Dec 31 '18 at 21:40
@Fogmeister I tried that and setting a fixed width to the view or the label fixes the problem.
– Andras Karpati
Jan 1 at 14:52
@Fogmeister I tried that and setting a fixed width to the view or the label fixes the problem.
– Andras Karpati
Jan 1 at 14:52
add a comment |
1 Answer
1
active
oldest
votes
SOLUTION
I figured out that if I set the bubble view's leading constant the following:
Align leading to Superview
Constant: 0
Priority: 1000
Multiplier: 0.25
In order to set the maximum width to 75%, the label inside wraps incorrectly.
SO I deletet the leading constraint and instead of that I maximize the width via aspect-ratio!
If I use aspect-ratio 2:3
Then I achieve the same outcome, but with the label wrapping correctly!!
Yay
SOLUTION 2.0
Okay, now I have figured out that the bubble view's leading constraint's second item (SuperView.Trailing) was Relative to Margin
After unchecking it, the problem gets fixed, so I don't have to use aspect ratio! Yay
BUT PAY ATTENTION
Because using Line Break: Word Wrap
also causes some problems.
Sometimes it tries to break the text into a new line (minimum 2 words) but if the cell was reused then the app might calculate wrong height for the view.
First picture: Word Wrap
- - - - - - - Second picture: Clip
Maybe this issue can be fixed with layoutIfNeeded() or i don't know. Clip is fine for me
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%2f53982102%2ftableview-calculates-wrong-height-for-dynamic-widthheight-label%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
SOLUTION
I figured out that if I set the bubble view's leading constant the following:
Align leading to Superview
Constant: 0
Priority: 1000
Multiplier: 0.25
In order to set the maximum width to 75%, the label inside wraps incorrectly.
SO I deletet the leading constraint and instead of that I maximize the width via aspect-ratio!
If I use aspect-ratio 2:3
Then I achieve the same outcome, but with the label wrapping correctly!!
Yay
SOLUTION 2.0
Okay, now I have figured out that the bubble view's leading constraint's second item (SuperView.Trailing) was Relative to Margin
After unchecking it, the problem gets fixed, so I don't have to use aspect ratio! Yay
BUT PAY ATTENTION
Because using Line Break: Word Wrap
also causes some problems.
Sometimes it tries to break the text into a new line (minimum 2 words) but if the cell was reused then the app might calculate wrong height for the view.
First picture: Word Wrap
- - - - - - - Second picture: Clip
Maybe this issue can be fixed with layoutIfNeeded() or i don't know. Clip is fine for me
add a comment |
SOLUTION
I figured out that if I set the bubble view's leading constant the following:
Align leading to Superview
Constant: 0
Priority: 1000
Multiplier: 0.25
In order to set the maximum width to 75%, the label inside wraps incorrectly.
SO I deletet the leading constraint and instead of that I maximize the width via aspect-ratio!
If I use aspect-ratio 2:3
Then I achieve the same outcome, but with the label wrapping correctly!!
Yay
SOLUTION 2.0
Okay, now I have figured out that the bubble view's leading constraint's second item (SuperView.Trailing) was Relative to Margin
After unchecking it, the problem gets fixed, so I don't have to use aspect ratio! Yay
BUT PAY ATTENTION
Because using Line Break: Word Wrap
also causes some problems.
Sometimes it tries to break the text into a new line (minimum 2 words) but if the cell was reused then the app might calculate wrong height for the view.
First picture: Word Wrap
- - - - - - - Second picture: Clip
Maybe this issue can be fixed with layoutIfNeeded() or i don't know. Clip is fine for me
add a comment |
SOLUTION
I figured out that if I set the bubble view's leading constant the following:
Align leading to Superview
Constant: 0
Priority: 1000
Multiplier: 0.25
In order to set the maximum width to 75%, the label inside wraps incorrectly.
SO I deletet the leading constraint and instead of that I maximize the width via aspect-ratio!
If I use aspect-ratio 2:3
Then I achieve the same outcome, but with the label wrapping correctly!!
Yay
SOLUTION 2.0
Okay, now I have figured out that the bubble view's leading constraint's second item (SuperView.Trailing) was Relative to Margin
After unchecking it, the problem gets fixed, so I don't have to use aspect ratio! Yay
BUT PAY ATTENTION
Because using Line Break: Word Wrap
also causes some problems.
Sometimes it tries to break the text into a new line (minimum 2 words) but if the cell was reused then the app might calculate wrong height for the view.
First picture: Word Wrap
- - - - - - - Second picture: Clip
Maybe this issue can be fixed with layoutIfNeeded() or i don't know. Clip is fine for me
SOLUTION
I figured out that if I set the bubble view's leading constant the following:
Align leading to Superview
Constant: 0
Priority: 1000
Multiplier: 0.25
In order to set the maximum width to 75%, the label inside wraps incorrectly.
SO I deletet the leading constraint and instead of that I maximize the width via aspect-ratio!
If I use aspect-ratio 2:3
Then I achieve the same outcome, but with the label wrapping correctly!!
Yay
SOLUTION 2.0
Okay, now I have figured out that the bubble view's leading constraint's second item (SuperView.Trailing) was Relative to Margin
After unchecking it, the problem gets fixed, so I don't have to use aspect ratio! Yay
BUT PAY ATTENTION
Because using Line Break: Word Wrap
also causes some problems.
Sometimes it tries to break the text into a new line (minimum 2 words) but if the cell was reused then the app might calculate wrong height for the view.
First picture: Word Wrap
- - - - - - - Second picture: Clip
Maybe this issue can be fixed with layoutIfNeeded() or i don't know. Clip is fine for me
edited Jan 2 at 2:35
answered Dec 31 '18 at 16:44
Andras KarpatiAndras Karpati
124117
124117
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.
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%2f53982102%2ftableview-calculates-wrong-height-for-dynamic-widthheight-label%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
2
i suggest you to use manual calculation for best performance or you can use hight caching mechanism which give you average performance
– SPatel
Dec 31 '18 at 4:29
1
If you have a solution, post it as an answer, not as part of the question. Or else delete the question so it doesn’t go on sitting here.
– matt
Dec 31 '18 at 16:32
1
What happens if you fix the width? Currently they have variable width. Set it to a fixed width just to try.
– Fogmeister
Dec 31 '18 at 21:40
@Fogmeister I tried that and setting a fixed width to the view or the label fixes the problem.
– Andras Karpati
Jan 1 at 14:52