Collectionviews move weird when setting constraints
I got three collectionViews
in my application. Now I finished it as far as I wanted it to complete. The only problem which I have for several days now are the constraints. I don't know how to explain it in words so I added two pictures of the problem to the question I hope it's understandable.
What I currently have:
What I want:
ios swift xcode constraints collectionview
add a comment |
I got three collectionViews
in my application. Now I finished it as far as I wanted it to complete. The only problem which I have for several days now are the constraints. I don't know how to explain it in words so I added two pictures of the problem to the question I hope it's understandable.
What I currently have:
What I want:
ios swift xcode constraints collectionview
Please mention what are you trying to achieve and what is the current state. The screenshot you've provided, cannot relate anything between them.
– Ratul Sharker
Nov 14 '18 at 10:09
The collectionView with the white dots has now two rows and I want, that - no matter what device - the first has always 4 rows, the second and the third 1 row.
– SWIFTstuff
Nov 14 '18 at 10:11
@SWIFTstuff - it's still not clear what you are asking. Can you show an image of how you want it to look?
– DonMag
Nov 14 '18 at 13:32
I added it on the top of the other screenshot
– SWIFTstuff
Nov 14 '18 at 14:02
add a comment |
I got three collectionViews
in my application. Now I finished it as far as I wanted it to complete. The only problem which I have for several days now are the constraints. I don't know how to explain it in words so I added two pictures of the problem to the question I hope it's understandable.
What I currently have:
What I want:
ios swift xcode constraints collectionview
I got three collectionViews
in my application. Now I finished it as far as I wanted it to complete. The only problem which I have for several days now are the constraints. I don't know how to explain it in words so I added two pictures of the problem to the question I hope it's understandable.
What I currently have:
What I want:
ios swift xcode constraints collectionview
ios swift xcode constraints collectionview
edited Nov 14 '18 at 14:28
DonMag
16.3k21028
16.3k21028
asked Nov 14 '18 at 10:06
SWIFTstuffSWIFTstuff
187
187
Please mention what are you trying to achieve and what is the current state. The screenshot you've provided, cannot relate anything between them.
– Ratul Sharker
Nov 14 '18 at 10:09
The collectionView with the white dots has now two rows and I want, that - no matter what device - the first has always 4 rows, the second and the third 1 row.
– SWIFTstuff
Nov 14 '18 at 10:11
@SWIFTstuff - it's still not clear what you are asking. Can you show an image of how you want it to look?
– DonMag
Nov 14 '18 at 13:32
I added it on the top of the other screenshot
– SWIFTstuff
Nov 14 '18 at 14:02
add a comment |
Please mention what are you trying to achieve and what is the current state. The screenshot you've provided, cannot relate anything between them.
– Ratul Sharker
Nov 14 '18 at 10:09
The collectionView with the white dots has now two rows and I want, that - no matter what device - the first has always 4 rows, the second and the third 1 row.
– SWIFTstuff
Nov 14 '18 at 10:11
@SWIFTstuff - it's still not clear what you are asking. Can you show an image of how you want it to look?
– DonMag
Nov 14 '18 at 13:32
I added it on the top of the other screenshot
– SWIFTstuff
Nov 14 '18 at 14:02
Please mention what are you trying to achieve and what is the current state. The screenshot you've provided, cannot relate anything between them.
– Ratul Sharker
Nov 14 '18 at 10:09
Please mention what are you trying to achieve and what is the current state. The screenshot you've provided, cannot relate anything between them.
– Ratul Sharker
Nov 14 '18 at 10:09
The collectionView with the white dots has now two rows and I want, that - no matter what device - the first has always 4 rows, the second and the third 1 row.
– SWIFTstuff
Nov 14 '18 at 10:11
The collectionView with the white dots has now two rows and I want, that - no matter what device - the first has always 4 rows, the second and the third 1 row.
– SWIFTstuff
Nov 14 '18 at 10:11
@SWIFTstuff - it's still not clear what you are asking. Can you show an image of how you want it to look?
– DonMag
Nov 14 '18 at 13:32
@SWIFTstuff - it's still not clear what you are asking. Can you show an image of how you want it to look?
– DonMag
Nov 14 '18 at 13:32
I added it on the top of the other screenshot
– SWIFTstuff
Nov 14 '18 at 14:02
I added it on the top of the other screenshot
– SWIFTstuff
Nov 14 '18 at 14:02
add a comment |
2 Answers
2
active
oldest
votes
Use UICollectionViewDelegateFlowLayout
delegate method to archive this.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
in this method, you can programmatically set size of cells. Give sizes according to your need of each collectionView.
add a comment |
Based on your screenshots, it looks like the collection view holding the column of white dots expands its width when the superview (the screen size) changes.
It also looks like you are using Flow Layout... when the view gets wider there is enough room for 2 cells on each row.
You should be able to fix that by either:
- constraining the width of that collection view so it doesn't expand, or
- using a custom Collection View Layout
I'd suggest trying a width constraint first - see if you can get the layout to look the way you want.
As a side note... using collection views may not be the best approach for what you're trying to do. UIStackView
might be a better option (although, I don't know what else the interface will be doing, so maybe not).
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%2f53297580%2fcollectionviews-move-weird-when-setting-constraints%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
Use UICollectionViewDelegateFlowLayout
delegate method to archive this.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
in this method, you can programmatically set size of cells. Give sizes according to your need of each collectionView.
add a comment |
Use UICollectionViewDelegateFlowLayout
delegate method to archive this.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
in this method, you can programmatically set size of cells. Give sizes according to your need of each collectionView.
add a comment |
Use UICollectionViewDelegateFlowLayout
delegate method to archive this.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
in this method, you can programmatically set size of cells. Give sizes according to your need of each collectionView.
Use UICollectionViewDelegateFlowLayout
delegate method to archive this.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
in this method, you can programmatically set size of cells. Give sizes according to your need of each collectionView.
answered Nov 14 '18 at 13:20
Kiran PadhiyarKiran Padhiyar
113
113
add a comment |
add a comment |
Based on your screenshots, it looks like the collection view holding the column of white dots expands its width when the superview (the screen size) changes.
It also looks like you are using Flow Layout... when the view gets wider there is enough room for 2 cells on each row.
You should be able to fix that by either:
- constraining the width of that collection view so it doesn't expand, or
- using a custom Collection View Layout
I'd suggest trying a width constraint first - see if you can get the layout to look the way you want.
As a side note... using collection views may not be the best approach for what you're trying to do. UIStackView
might be a better option (although, I don't know what else the interface will be doing, so maybe not).
add a comment |
Based on your screenshots, it looks like the collection view holding the column of white dots expands its width when the superview (the screen size) changes.
It also looks like you are using Flow Layout... when the view gets wider there is enough room for 2 cells on each row.
You should be able to fix that by either:
- constraining the width of that collection view so it doesn't expand, or
- using a custom Collection View Layout
I'd suggest trying a width constraint first - see if you can get the layout to look the way you want.
As a side note... using collection views may not be the best approach for what you're trying to do. UIStackView
might be a better option (although, I don't know what else the interface will be doing, so maybe not).
add a comment |
Based on your screenshots, it looks like the collection view holding the column of white dots expands its width when the superview (the screen size) changes.
It also looks like you are using Flow Layout... when the view gets wider there is enough room for 2 cells on each row.
You should be able to fix that by either:
- constraining the width of that collection view so it doesn't expand, or
- using a custom Collection View Layout
I'd suggest trying a width constraint first - see if you can get the layout to look the way you want.
As a side note... using collection views may not be the best approach for what you're trying to do. UIStackView
might be a better option (although, I don't know what else the interface will be doing, so maybe not).
Based on your screenshots, it looks like the collection view holding the column of white dots expands its width when the superview (the screen size) changes.
It also looks like you are using Flow Layout... when the view gets wider there is enough room for 2 cells on each row.
You should be able to fix that by either:
- constraining the width of that collection view so it doesn't expand, or
- using a custom Collection View Layout
I'd suggest trying a width constraint first - see if you can get the layout to look the way you want.
As a side note... using collection views may not be the best approach for what you're trying to do. UIStackView
might be a better option (although, I don't know what else the interface will be doing, so maybe not).
answered Nov 14 '18 at 14:37
DonMagDonMag
16.3k21028
16.3k21028
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%2f53297580%2fcollectionviews-move-weird-when-setting-constraints%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
Please mention what are you trying to achieve and what is the current state. The screenshot you've provided, cannot relate anything between them.
– Ratul Sharker
Nov 14 '18 at 10:09
The collectionView with the white dots has now two rows and I want, that - no matter what device - the first has always 4 rows, the second and the third 1 row.
– SWIFTstuff
Nov 14 '18 at 10:11
@SWIFTstuff - it's still not clear what you are asking. Can you show an image of how you want it to look?
– DonMag
Nov 14 '18 at 13:32
I added it on the top of the other screenshot
– SWIFTstuff
Nov 14 '18 at 14:02