UIImage in a UIcollectonView issue












0














I am trying to add a UIImage to the UICollectionViewController by using the following code:



let backgroundImage = UIImageView(frame: CGRect(x: 0, y: 0, width: 430, height: 550))
backgroundImage.image = UIImage(named: "fantasy_football_hero_tile_cropped.png")
backgroundImage.contentMode = UIView.ContentMode.scaleAspectFit
backgroundImage.clipsToBounds = true
self.view.insertSubview(backgroundImage, at: 0)


My issue is that the image is not at the bottom/lowest part of the screen which is what I am trying to achieve... how can I clip it to the bottom?! I am not using story board, can I programmatically anchor the image to the bottom as I could do in a storyboard?



This is especially true since the screen sizes for the phones are different, but the desire is still to have it anchored to the bottom.










share|improve this question






















  • "My issue is that the image is not at the bottom/lowest part of the screen" But you yourself are the one saying CGRect(x: 0, y: 0, width: 430, height: 550). That puts the image view at the top left corner. So it makes little sense to complain that the image view is located at the wrong place; it is located exactly where you put it.
    – matt
    Nov 21 at 3:13
















0














I am trying to add a UIImage to the UICollectionViewController by using the following code:



let backgroundImage = UIImageView(frame: CGRect(x: 0, y: 0, width: 430, height: 550))
backgroundImage.image = UIImage(named: "fantasy_football_hero_tile_cropped.png")
backgroundImage.contentMode = UIView.ContentMode.scaleAspectFit
backgroundImage.clipsToBounds = true
self.view.insertSubview(backgroundImage, at: 0)


My issue is that the image is not at the bottom/lowest part of the screen which is what I am trying to achieve... how can I clip it to the bottom?! I am not using story board, can I programmatically anchor the image to the bottom as I could do in a storyboard?



This is especially true since the screen sizes for the phones are different, but the desire is still to have it anchored to the bottom.










share|improve this question






















  • "My issue is that the image is not at the bottom/lowest part of the screen" But you yourself are the one saying CGRect(x: 0, y: 0, width: 430, height: 550). That puts the image view at the top left corner. So it makes little sense to complain that the image view is located at the wrong place; it is located exactly where you put it.
    – matt
    Nov 21 at 3:13














0












0








0







I am trying to add a UIImage to the UICollectionViewController by using the following code:



let backgroundImage = UIImageView(frame: CGRect(x: 0, y: 0, width: 430, height: 550))
backgroundImage.image = UIImage(named: "fantasy_football_hero_tile_cropped.png")
backgroundImage.contentMode = UIView.ContentMode.scaleAspectFit
backgroundImage.clipsToBounds = true
self.view.insertSubview(backgroundImage, at: 0)


My issue is that the image is not at the bottom/lowest part of the screen which is what I am trying to achieve... how can I clip it to the bottom?! I am not using story board, can I programmatically anchor the image to the bottom as I could do in a storyboard?



This is especially true since the screen sizes for the phones are different, but the desire is still to have it anchored to the bottom.










share|improve this question













I am trying to add a UIImage to the UICollectionViewController by using the following code:



let backgroundImage = UIImageView(frame: CGRect(x: 0, y: 0, width: 430, height: 550))
backgroundImage.image = UIImage(named: "fantasy_football_hero_tile_cropped.png")
backgroundImage.contentMode = UIView.ContentMode.scaleAspectFit
backgroundImage.clipsToBounds = true
self.view.insertSubview(backgroundImage, at: 0)


My issue is that the image is not at the bottom/lowest part of the screen which is what I am trying to achieve... how can I clip it to the bottom?! I am not using story board, can I programmatically anchor the image to the bottom as I could do in a storyboard?



This is especially true since the screen sizes for the phones are different, but the desire is still to have it anchored to the bottom.







swift uicollectionview uiimage






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 2:28









Famic Tech

181216




181216












  • "My issue is that the image is not at the bottom/lowest part of the screen" But you yourself are the one saying CGRect(x: 0, y: 0, width: 430, height: 550). That puts the image view at the top left corner. So it makes little sense to complain that the image view is located at the wrong place; it is located exactly where you put it.
    – matt
    Nov 21 at 3:13


















  • "My issue is that the image is not at the bottom/lowest part of the screen" But you yourself are the one saying CGRect(x: 0, y: 0, width: 430, height: 550). That puts the image view at the top left corner. So it makes little sense to complain that the image view is located at the wrong place; it is located exactly where you put it.
    – matt
    Nov 21 at 3:13
















"My issue is that the image is not at the bottom/lowest part of the screen" But you yourself are the one saying CGRect(x: 0, y: 0, width: 430, height: 550). That puts the image view at the top left corner. So it makes little sense to complain that the image view is located at the wrong place; it is located exactly where you put it.
– matt
Nov 21 at 3:13




"My issue is that the image is not at the bottom/lowest part of the screen" But you yourself are the one saying CGRect(x: 0, y: 0, width: 430, height: 550). That puts the image view at the top left corner. So it makes little sense to complain that the image view is located at the wrong place; it is located exactly where you put it.
– matt
Nov 21 at 3:13












2 Answers
2






active

oldest

votes


















0














you can add programatically. I think you add/insert some views to the self.view that will also affect simple scenario



let backgroundImageV = UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 500))
backgroundImageV.backgroundColor = UIColor.blue
backgroundImageV.contentMode = UIView.ContentMode.scaleAspectFit
backgroundImageV.clipsToBounds = true
self.view.addSubview(backgroundImageV)


let backgroundImageV2 = UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 510))
backgroundImageV2.backgroundColor = UIColor.green
backgroundImageV2.contentMode = UIView.ContentMode.scaleAspectFit
backgroundImageV2.clipsToBounds = true
self.view.insertSubview(backgroundImageV2, at: 0)

let backgroundImage = UIImageView(frame: CGRect(x: 0, y: 0, width: 430, height: 550))
backgroundImage.backgroundColor = UIColor.red
backgroundImage.contentMode = UIView.ContentMode.scaleAspectFit
backgroundImage.clipsToBounds = true
self.view.insertSubview(backgroundImage, at: 0)


Here Red will be bottom Green will be in 1. because you add that red colored view later. So It will work. Can you please show your full code. It will work






share|improve this answer





























    0














    One problem here is that self.view for a UICollectionViewController is the UICollectionView. This is a scroll view, so no matter where you put this image view, it is going to move when the scroll view scrolls.



    If that isn't what you want, there is a simple solution: set the image view as the collection view's backgroundView. That is a stationary view that forms the background to the collection view no matter how it is scrolled. If you set the image view's contentMode to bottom the image will be centered at the bottom, which seems to be what you are after.






    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%2f53404493%2fuiimage-in-a-uicollectonview-issue%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














      you can add programatically. I think you add/insert some views to the self.view that will also affect simple scenario



      let backgroundImageV = UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 500))
      backgroundImageV.backgroundColor = UIColor.blue
      backgroundImageV.contentMode = UIView.ContentMode.scaleAspectFit
      backgroundImageV.clipsToBounds = true
      self.view.addSubview(backgroundImageV)


      let backgroundImageV2 = UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 510))
      backgroundImageV2.backgroundColor = UIColor.green
      backgroundImageV2.contentMode = UIView.ContentMode.scaleAspectFit
      backgroundImageV2.clipsToBounds = true
      self.view.insertSubview(backgroundImageV2, at: 0)

      let backgroundImage = UIImageView(frame: CGRect(x: 0, y: 0, width: 430, height: 550))
      backgroundImage.backgroundColor = UIColor.red
      backgroundImage.contentMode = UIView.ContentMode.scaleAspectFit
      backgroundImage.clipsToBounds = true
      self.view.insertSubview(backgroundImage, at: 0)


      Here Red will be bottom Green will be in 1. because you add that red colored view later. So It will work. Can you please show your full code. It will work






      share|improve this answer


























        0














        you can add programatically. I think you add/insert some views to the self.view that will also affect simple scenario



        let backgroundImageV = UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 500))
        backgroundImageV.backgroundColor = UIColor.blue
        backgroundImageV.contentMode = UIView.ContentMode.scaleAspectFit
        backgroundImageV.clipsToBounds = true
        self.view.addSubview(backgroundImageV)


        let backgroundImageV2 = UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 510))
        backgroundImageV2.backgroundColor = UIColor.green
        backgroundImageV2.contentMode = UIView.ContentMode.scaleAspectFit
        backgroundImageV2.clipsToBounds = true
        self.view.insertSubview(backgroundImageV2, at: 0)

        let backgroundImage = UIImageView(frame: CGRect(x: 0, y: 0, width: 430, height: 550))
        backgroundImage.backgroundColor = UIColor.red
        backgroundImage.contentMode = UIView.ContentMode.scaleAspectFit
        backgroundImage.clipsToBounds = true
        self.view.insertSubview(backgroundImage, at: 0)


        Here Red will be bottom Green will be in 1. because you add that red colored view later. So It will work. Can you please show your full code. It will work






        share|improve this answer
























          0












          0








          0






          you can add programatically. I think you add/insert some views to the self.view that will also affect simple scenario



          let backgroundImageV = UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 500))
          backgroundImageV.backgroundColor = UIColor.blue
          backgroundImageV.contentMode = UIView.ContentMode.scaleAspectFit
          backgroundImageV.clipsToBounds = true
          self.view.addSubview(backgroundImageV)


          let backgroundImageV2 = UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 510))
          backgroundImageV2.backgroundColor = UIColor.green
          backgroundImageV2.contentMode = UIView.ContentMode.scaleAspectFit
          backgroundImageV2.clipsToBounds = true
          self.view.insertSubview(backgroundImageV2, at: 0)

          let backgroundImage = UIImageView(frame: CGRect(x: 0, y: 0, width: 430, height: 550))
          backgroundImage.backgroundColor = UIColor.red
          backgroundImage.contentMode = UIView.ContentMode.scaleAspectFit
          backgroundImage.clipsToBounds = true
          self.view.insertSubview(backgroundImage, at: 0)


          Here Red will be bottom Green will be in 1. because you add that red colored view later. So It will work. Can you please show your full code. It will work






          share|improve this answer












          you can add programatically. I think you add/insert some views to the self.view that will also affect simple scenario



          let backgroundImageV = UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 500))
          backgroundImageV.backgroundColor = UIColor.blue
          backgroundImageV.contentMode = UIView.ContentMode.scaleAspectFit
          backgroundImageV.clipsToBounds = true
          self.view.addSubview(backgroundImageV)


          let backgroundImageV2 = UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 510))
          backgroundImageV2.backgroundColor = UIColor.green
          backgroundImageV2.contentMode = UIView.ContentMode.scaleAspectFit
          backgroundImageV2.clipsToBounds = true
          self.view.insertSubview(backgroundImageV2, at: 0)

          let backgroundImage = UIImageView(frame: CGRect(x: 0, y: 0, width: 430, height: 550))
          backgroundImage.backgroundColor = UIColor.red
          backgroundImage.contentMode = UIView.ContentMode.scaleAspectFit
          backgroundImage.clipsToBounds = true
          self.view.insertSubview(backgroundImage, at: 0)


          Here Red will be bottom Green will be in 1. because you add that red colored view later. So It will work. Can you please show your full code. It will work







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 at 3:07









          Ruban4Axis

          17313




          17313

























              0














              One problem here is that self.view for a UICollectionViewController is the UICollectionView. This is a scroll view, so no matter where you put this image view, it is going to move when the scroll view scrolls.



              If that isn't what you want, there is a simple solution: set the image view as the collection view's backgroundView. That is a stationary view that forms the background to the collection view no matter how it is scrolled. If you set the image view's contentMode to bottom the image will be centered at the bottom, which seems to be what you are after.






              share|improve this answer


























                0














                One problem here is that self.view for a UICollectionViewController is the UICollectionView. This is a scroll view, so no matter where you put this image view, it is going to move when the scroll view scrolls.



                If that isn't what you want, there is a simple solution: set the image view as the collection view's backgroundView. That is a stationary view that forms the background to the collection view no matter how it is scrolled. If you set the image view's contentMode to bottom the image will be centered at the bottom, which seems to be what you are after.






                share|improve this answer
























                  0












                  0








                  0






                  One problem here is that self.view for a UICollectionViewController is the UICollectionView. This is a scroll view, so no matter where you put this image view, it is going to move when the scroll view scrolls.



                  If that isn't what you want, there is a simple solution: set the image view as the collection view's backgroundView. That is a stationary view that forms the background to the collection view no matter how it is scrolled. If you set the image view's contentMode to bottom the image will be centered at the bottom, which seems to be what you are after.






                  share|improve this answer












                  One problem here is that self.view for a UICollectionViewController is the UICollectionView. This is a scroll view, so no matter where you put this image view, it is going to move when the scroll view scrolls.



                  If that isn't what you want, there is a simple solution: set the image view as the collection view's backgroundView. That is a stationary view that forms the background to the collection view no matter how it is scrolled. If you set the image view's contentMode to bottom the image will be centered at the bottom, which seems to be what you are after.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 at 3:16









                  matt

                  322k45519720




                  322k45519720






























                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2f53404493%2fuiimage-in-a-uicollectonview-issue%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

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      Refactoring coordinates for Minecraft Pi buildings written in Python