Collectionviews move weird when setting constraints












0















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:












share|improve this question

























  • 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
















0















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:












share|improve this question

























  • 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














0












0








0








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:












share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












2 Answers
2






active

oldest

votes


















0














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.






share|improve this answer































    0














    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).






    share|improve this answer























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      0














      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.






      share|improve this answer




























        0














        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.






        share|improve this answer


























          0












          0








          0







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 13:20









          Kiran PadhiyarKiran Padhiyar

          113




          113

























              0














              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).






              share|improve this answer




























                0














                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).






                share|improve this answer


























                  0












                  0








                  0







                  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).






                  share|improve this answer













                  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).







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 14:37









                  DonMagDonMag

                  16.3k21028




                  16.3k21028






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine