Multi Line Labels and an Image with UIStackView
I am trying to see if I can easily use a UIStackView to create multi line labels and also display an image.
Here are my current constraints.

When I run it I get the following:

If I remove the imageview then the multi line works. Somehow UIImageView width and height is messing up everything. What am I doing wrong?
ios uistackview
add a comment |
I am trying to see if I can easily use a UIStackView to create multi line labels and also display an image.
Here are my current constraints.

When I run it I get the following:

If I remove the imageview then the multi line works. Somehow UIImageView width and height is messing up everything. What am I doing wrong?
ios uistackview
Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.
– Dare
Jan 3 at 19:35
Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.
– john doe
Jan 3 at 19:40
1
In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.
– Dare
Jan 3 at 19:42
Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.
– john doe
Jan 3 at 19:43
add a comment |
I am trying to see if I can easily use a UIStackView to create multi line labels and also display an image.
Here are my current constraints.

When I run it I get the following:

If I remove the imageview then the multi line works. Somehow UIImageView width and height is messing up everything. What am I doing wrong?
ios uistackview
I am trying to see if I can easily use a UIStackView to create multi line labels and also display an image.
Here are my current constraints.

When I run it I get the following:

If I remove the imageview then the multi line works. Somehow UIImageView width and height is messing up everything. What am I doing wrong?
ios uistackview
ios uistackview
edited Jan 3 at 19:30
rmaddy
246k27327390
246k27327390
asked Jan 3 at 19:27
john doejohn doe
3,039124398
3,039124398
Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.
– Dare
Jan 3 at 19:35
Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.
– john doe
Jan 3 at 19:40
1
In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.
– Dare
Jan 3 at 19:42
Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.
– john doe
Jan 3 at 19:43
add a comment |
Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.
– Dare
Jan 3 at 19:35
Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.
– john doe
Jan 3 at 19:40
1
In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.
– Dare
Jan 3 at 19:42
Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.
– john doe
Jan 3 at 19:43
Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.
– Dare
Jan 3 at 19:35
Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.
– Dare
Jan 3 at 19:35
Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.
– john doe
Jan 3 at 19:40
Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.
– john doe
Jan 3 at 19:40
1
1
In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.
– Dare
Jan 3 at 19:42
In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.
– Dare
Jan 3 at 19:42
Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.
– john doe
Jan 3 at 19:43
Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.
– john doe
Jan 3 at 19:43
add a comment |
2 Answers
2
active
oldest
votes
StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.
PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.
add a comment |
Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.

THis is how it will look like

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%2f54028617%2fmulti-line-labels-and-an-image-with-uistackview%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
StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.
PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.
add a comment |
StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.
PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.
add a comment |
StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.
PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.
StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.
PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.
answered Jan 3 at 19:48
emrepunemrepun
1,4662619
1,4662619
add a comment |
add a comment |
Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.

THis is how it will look like

add a comment |
Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.

THis is how it will look like

add a comment |
Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.

THis is how it will look like

Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.

THis is how it will look like

answered Jan 3 at 22:15
Viren PatelViren Patel
3817
3817
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%2f54028617%2fmulti-line-labels-and-an-image-with-uistackview%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
Is your stack view horizontal and embedded in a UITableView cell with another embedded vertical stack view inside of it? I think there's a lot of extra hands in the pot when you're laying out. I would likely try and lose the 2nd nested vertical stack and calculate the height of the cells instead.
– Dare
Jan 3 at 19:35
Yes exactly. I have a UITableViewCell. Inside the cell I have a parent stackview. Inside the stackview I have another vertical stackview which contains the label. In the parent stackview I also have uiimageview. If I loose the vertical stackview then uilabels will not align vertically.
– john doe
Jan 3 at 19:40
1
In my personal opinion, both of those stack views are unnecessary. I think you can accomplish what you want with layout constraints and add your subviews directly to the cell.
– Dare
Jan 3 at 19:42
Yes! I was able to accomplish that easily without UIStackView. I just wanted to see if it was easier when using UIStackView or not. I guess not.
– john doe
Jan 3 at 19:43