UIImageView in UIScrollView with Autolayout constraints appear messed up





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a scrollview on a normal UIView. Set the correct constraints for it. Scrollview size is working fine when running the app. But the problem appears for the UIImageView in this scrollview.



I have added "typical" constraints to the UIImageView - trailing, leading, bottom space, and top space to 0 relative to UIScrollView. I also added Align Center X and Y to UIScrollView.



I have also set the contentMode to "AspectFit" to the UIImageView, but when I load a landscape oriented image, the image appears stretched following the UIImageView size (which fills up the UIScrollView).



How to fix this? Or do I need to remove the UIImageView constraints and manually setting the UIImageView size at runtime?










share|improve this question























  • You must be missing something... For one, your UIImageView needs Width and Height constraints. The leading/trailing/top/bottom constraints define the .contentSize of the scroll view. Are you laying this out in IB? If so, when you set an image there, does it get "stretched" or does it correctly use the Aspect Fit mode?

    – DonMag
    Nov 27 '18 at 18:42











  • Yes, am laying it out using storyboard IB. How do I set Width and Height constraints together with leading/trail/top/bottom? Won't that cause conflicts?

    – GeneCode
    Nov 27 '18 at 23:39











  • I'm assuming you are putting this image view inside a scroll view so you can Zoom? That is, you're not adding anything else (such as multiple image views to scroll left-right)?

    – DonMag
    Nov 28 '18 at 13:48











  • @DonMag, yes there is just one scrollview and one imageview. It is like a single image viewer.

    – GeneCode
    Dec 1 '18 at 0:27











  • Possible duplicate of setting UIImageView content mode after applying a CIFIlter

    – GeneCode
    Dec 1 '18 at 1:03


















0















I have a scrollview on a normal UIView. Set the correct constraints for it. Scrollview size is working fine when running the app. But the problem appears for the UIImageView in this scrollview.



I have added "typical" constraints to the UIImageView - trailing, leading, bottom space, and top space to 0 relative to UIScrollView. I also added Align Center X and Y to UIScrollView.



I have also set the contentMode to "AspectFit" to the UIImageView, but when I load a landscape oriented image, the image appears stretched following the UIImageView size (which fills up the UIScrollView).



How to fix this? Or do I need to remove the UIImageView constraints and manually setting the UIImageView size at runtime?










share|improve this question























  • You must be missing something... For one, your UIImageView needs Width and Height constraints. The leading/trailing/top/bottom constraints define the .contentSize of the scroll view. Are you laying this out in IB? If so, when you set an image there, does it get "stretched" or does it correctly use the Aspect Fit mode?

    – DonMag
    Nov 27 '18 at 18:42











  • Yes, am laying it out using storyboard IB. How do I set Width and Height constraints together with leading/trail/top/bottom? Won't that cause conflicts?

    – GeneCode
    Nov 27 '18 at 23:39











  • I'm assuming you are putting this image view inside a scroll view so you can Zoom? That is, you're not adding anything else (such as multiple image views to scroll left-right)?

    – DonMag
    Nov 28 '18 at 13:48











  • @DonMag, yes there is just one scrollview and one imageview. It is like a single image viewer.

    – GeneCode
    Dec 1 '18 at 0:27











  • Possible duplicate of setting UIImageView content mode after applying a CIFIlter

    – GeneCode
    Dec 1 '18 at 1:03














0












0








0


1






I have a scrollview on a normal UIView. Set the correct constraints for it. Scrollview size is working fine when running the app. But the problem appears for the UIImageView in this scrollview.



I have added "typical" constraints to the UIImageView - trailing, leading, bottom space, and top space to 0 relative to UIScrollView. I also added Align Center X and Y to UIScrollView.



I have also set the contentMode to "AspectFit" to the UIImageView, but when I load a landscape oriented image, the image appears stretched following the UIImageView size (which fills up the UIScrollView).



How to fix this? Or do I need to remove the UIImageView constraints and manually setting the UIImageView size at runtime?










share|improve this question














I have a scrollview on a normal UIView. Set the correct constraints for it. Scrollview size is working fine when running the app. But the problem appears for the UIImageView in this scrollview.



I have added "typical" constraints to the UIImageView - trailing, leading, bottom space, and top space to 0 relative to UIScrollView. I also added Align Center X and Y to UIScrollView.



I have also set the contentMode to "AspectFit" to the UIImageView, but when I load a landscape oriented image, the image appears stretched following the UIImageView size (which fills up the UIScrollView).



How to fix this? Or do I need to remove the UIImageView constraints and manually setting the UIImageView size at runtime?







xcode uiscrollview uiimageview autolayout constraints






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 3:35









GeneCodeGeneCode

5,70053565




5,70053565













  • You must be missing something... For one, your UIImageView needs Width and Height constraints. The leading/trailing/top/bottom constraints define the .contentSize of the scroll view. Are you laying this out in IB? If so, when you set an image there, does it get "stretched" or does it correctly use the Aspect Fit mode?

    – DonMag
    Nov 27 '18 at 18:42











  • Yes, am laying it out using storyboard IB. How do I set Width and Height constraints together with leading/trail/top/bottom? Won't that cause conflicts?

    – GeneCode
    Nov 27 '18 at 23:39











  • I'm assuming you are putting this image view inside a scroll view so you can Zoom? That is, you're not adding anything else (such as multiple image views to scroll left-right)?

    – DonMag
    Nov 28 '18 at 13:48











  • @DonMag, yes there is just one scrollview and one imageview. It is like a single image viewer.

    – GeneCode
    Dec 1 '18 at 0:27











  • Possible duplicate of setting UIImageView content mode after applying a CIFIlter

    – GeneCode
    Dec 1 '18 at 1:03



















  • You must be missing something... For one, your UIImageView needs Width and Height constraints. The leading/trailing/top/bottom constraints define the .contentSize of the scroll view. Are you laying this out in IB? If so, when you set an image there, does it get "stretched" or does it correctly use the Aspect Fit mode?

    – DonMag
    Nov 27 '18 at 18:42











  • Yes, am laying it out using storyboard IB. How do I set Width and Height constraints together with leading/trail/top/bottom? Won't that cause conflicts?

    – GeneCode
    Nov 27 '18 at 23:39











  • I'm assuming you are putting this image view inside a scroll view so you can Zoom? That is, you're not adding anything else (such as multiple image views to scroll left-right)?

    – DonMag
    Nov 28 '18 at 13:48











  • @DonMag, yes there is just one scrollview and one imageview. It is like a single image viewer.

    – GeneCode
    Dec 1 '18 at 0:27











  • Possible duplicate of setting UIImageView content mode after applying a CIFIlter

    – GeneCode
    Dec 1 '18 at 1:03

















You must be missing something... For one, your UIImageView needs Width and Height constraints. The leading/trailing/top/bottom constraints define the .contentSize of the scroll view. Are you laying this out in IB? If so, when you set an image there, does it get "stretched" or does it correctly use the Aspect Fit mode?

– DonMag
Nov 27 '18 at 18:42





You must be missing something... For one, your UIImageView needs Width and Height constraints. The leading/trailing/top/bottom constraints define the .contentSize of the scroll view. Are you laying this out in IB? If so, when you set an image there, does it get "stretched" or does it correctly use the Aspect Fit mode?

– DonMag
Nov 27 '18 at 18:42













Yes, am laying it out using storyboard IB. How do I set Width and Height constraints together with leading/trail/top/bottom? Won't that cause conflicts?

– GeneCode
Nov 27 '18 at 23:39





Yes, am laying it out using storyboard IB. How do I set Width and Height constraints together with leading/trail/top/bottom? Won't that cause conflicts?

– GeneCode
Nov 27 '18 at 23:39













I'm assuming you are putting this image view inside a scroll view so you can Zoom? That is, you're not adding anything else (such as multiple image views to scroll left-right)?

– DonMag
Nov 28 '18 at 13:48





I'm assuming you are putting this image view inside a scroll view so you can Zoom? That is, you're not adding anything else (such as multiple image views to scroll left-right)?

– DonMag
Nov 28 '18 at 13:48













@DonMag, yes there is just one scrollview and one imageview. It is like a single image viewer.

– GeneCode
Dec 1 '18 at 0:27





@DonMag, yes there is just one scrollview and one imageview. It is like a single image viewer.

– GeneCode
Dec 1 '18 at 0:27













Possible duplicate of setting UIImageView content mode after applying a CIFIlter

– GeneCode
Dec 1 '18 at 1:03





Possible duplicate of setting UIImageView content mode after applying a CIFIlter

– GeneCode
Dec 1 '18 at 1:03












0






active

oldest

votes












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%2f53464435%2fuiimageview-in-uiscrollview-with-autolayout-constraints-appear-messed-up%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53464435%2fuiimageview-in-uiscrollview-with-autolayout-constraints-appear-messed-up%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







這個網誌中的熱門文章

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Xamarin.form Move up view when keyboard appear

JBPM : POST request for execute process go wrong