Not able to reduce UITableCustomCell height in iOS using Swift?
I need to reduce the height of the UITableView custom cell, if their is no data for the optional labels to show. following image would be a great help to understand
I tried assigning constraints constant value to 0 and 20 for the pre/post Instruction's respective top/bottom on the availability of data, it's working perfect when both optional values (pre/post instructions) are available, but in case of missing anyvalue the cell is picking the minimum height see below 👇👇
Altough in heightForRowAt method i'm returning
return UITableViewAutomaticDimension
If any of the optional value (On the yellow label) is missing, I need to manage the exterior space of that label in the cell, Please suggest me a better solution 👍👍
ios iphone swift uitableview uitableviewautomaticdimension
add a comment |
I need to reduce the height of the UITableView custom cell, if their is no data for the optional labels to show. following image would be a great help to understand
I tried assigning constraints constant value to 0 and 20 for the pre/post Instruction's respective top/bottom on the availability of data, it's working perfect when both optional values (pre/post instructions) are available, but in case of missing anyvalue the cell is picking the minimum height see below 👇👇
Altough in heightForRowAt method i'm returning
return UITableViewAutomaticDimension
If any of the optional value (On the yellow label) is missing, I need to manage the exterior space of that label in the cell, Please suggest me a better solution 👍👍
ios iphone swift uitableview uitableviewautomaticdimension
add a comment |
I need to reduce the height of the UITableView custom cell, if their is no data for the optional labels to show. following image would be a great help to understand
I tried assigning constraints constant value to 0 and 20 for the pre/post Instruction's respective top/bottom on the availability of data, it's working perfect when both optional values (pre/post instructions) are available, but in case of missing anyvalue the cell is picking the minimum height see below 👇👇
Altough in heightForRowAt method i'm returning
return UITableViewAutomaticDimension
If any of the optional value (On the yellow label) is missing, I need to manage the exterior space of that label in the cell, Please suggest me a better solution 👍👍
ios iphone swift uitableview uitableviewautomaticdimension
I need to reduce the height of the UITableView custom cell, if their is no data for the optional labels to show. following image would be a great help to understand
I tried assigning constraints constant value to 0 and 20 for the pre/post Instruction's respective top/bottom on the availability of data, it's working perfect when both optional values (pre/post instructions) are available, but in case of missing anyvalue the cell is picking the minimum height see below 👇👇
Altough in heightForRowAt method i'm returning
return UITableViewAutomaticDimension
If any of the optional value (On the yellow label) is missing, I need to manage the exterior space of that label in the cell, Please suggest me a better solution 👍👍
ios iphone swift uitableview uitableviewautomaticdimension
ios iphone swift uitableview uitableviewautomaticdimension
edited Nov 20 '18 at 15:15
Mohit Garg
asked Nov 20 '18 at 15:07
Mohit GargMohit Garg
165139
165139
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
you can achieve this using a UIStackView.
Just embbed the Pre Instructions, Ingredient Name and Post Instruction inside a Vertical UIStackView, then add the constrains, 20 from top and bottom, whatever you want trailing and the spacing you want from the left label. And finally add the item spacing you want between the UIStackView items (4 o 8 pts for example).
Then, what you need to do is just hide the label when it has no content and the UIStackView will do the magic for you, it will handle the spacing when an item is hidden.
;)
thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)
– Mohit Garg
Nov 21 '18 at 5:39
@MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.
– Esteban Vallejo
Nov 23 '18 at 15:45
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%2f53395918%2fnot-able-to-reduce-uitablecustomcell-height-in-ios-using-swift%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
you can achieve this using a UIStackView.
Just embbed the Pre Instructions, Ingredient Name and Post Instruction inside a Vertical UIStackView, then add the constrains, 20 from top and bottom, whatever you want trailing and the spacing you want from the left label. And finally add the item spacing you want between the UIStackView items (4 o 8 pts for example).
Then, what you need to do is just hide the label when it has no content and the UIStackView will do the magic for you, it will handle the spacing when an item is hidden.
;)
thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)
– Mohit Garg
Nov 21 '18 at 5:39
@MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.
– Esteban Vallejo
Nov 23 '18 at 15:45
add a comment |
you can achieve this using a UIStackView.
Just embbed the Pre Instructions, Ingredient Name and Post Instruction inside a Vertical UIStackView, then add the constrains, 20 from top and bottom, whatever you want trailing and the spacing you want from the left label. And finally add the item spacing you want between the UIStackView items (4 o 8 pts for example).
Then, what you need to do is just hide the label when it has no content and the UIStackView will do the magic for you, it will handle the spacing when an item is hidden.
;)
thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)
– Mohit Garg
Nov 21 '18 at 5:39
@MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.
– Esteban Vallejo
Nov 23 '18 at 15:45
add a comment |
you can achieve this using a UIStackView.
Just embbed the Pre Instructions, Ingredient Name and Post Instruction inside a Vertical UIStackView, then add the constrains, 20 from top and bottom, whatever you want trailing and the spacing you want from the left label. And finally add the item spacing you want between the UIStackView items (4 o 8 pts for example).
Then, what you need to do is just hide the label when it has no content and the UIStackView will do the magic for you, it will handle the spacing when an item is hidden.
;)
you can achieve this using a UIStackView.
Just embbed the Pre Instructions, Ingredient Name and Post Instruction inside a Vertical UIStackView, then add the constrains, 20 from top and bottom, whatever you want trailing and the spacing you want from the left label. And finally add the item spacing you want between the UIStackView items (4 o 8 pts for example).
Then, what you need to do is just hide the label when it has no content and the UIStackView will do the magic for you, it will handle the spacing when an item is hidden.
;)
answered Nov 20 '18 at 15:29
Esteban VallejoEsteban Vallejo
22629
22629
thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)
– Mohit Garg
Nov 21 '18 at 5:39
@MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.
– Esteban Vallejo
Nov 23 '18 at 15:45
add a comment |
thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)
– Mohit Garg
Nov 21 '18 at 5:39
@MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.
– Esteban Vallejo
Nov 23 '18 at 15:45
thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)
– Mohit Garg
Nov 21 '18 at 5:39
thank you @Esteban for your opinion, earlier I was trying this with stack view but wasn't able to manage the leading and top space, because all these labels are multiple lines as well (Dynamic content length)
– Mohit Garg
Nov 21 '18 at 5:39
@MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.
– Esteban Vallejo
Nov 23 '18 at 15:45
@MohitGarg just by setting constraints and priorities correctly will work for multiple multi-line labels, just have in mind which one will stretch (huggin) and compress, which will be centered on the cell (I think the left label will always be centered relative to the right "stack") and so.
– Esteban Vallejo
Nov 23 '18 at 15:45
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%2f53395918%2fnot-able-to-reduce-uitablecustomcell-height-in-ios-using-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