Reputation: 41
This was a question asked by a user on Apple's cocoa-dev mailing list, who thought my answer would be helpful on Stack Overflow:
In XCode/IB, if add an Image View that has the Image property to an image in my project it shows the image scaled to fit the Frame of the Image View. How can I stop this and just truncate it? I want two images on top of each other and just show the top half of one and the bottom half of the other.
I see loads of scaling options in the “Content Mode” Property, but nothing to say “none”. The closest I’ve managed so far is to set the Content Mode to “Aspect Fit” and also set the clip to bounds. This does what I want BUT the centre of the image shows, not the top, left.
Basically, I have two 24 x 24 images placed one on top of the other, I want to show the first half (e.g. 0,0,24,12) of ImageA and the bottom half of imageB (e.g. 0,12,24,12).
Can I do this in XCode/IB? If not can I do this in code?
Upvotes: 2
Views: 107
Reputation: 41
Create two image views, set their sizes to 24 x 12, and set the Clip To Bounds property.
For one view, set its content mode to top (== top-center) or top-left, and the other to bottom (== bottom-center) or bottom-left.
If you turn off the clip property then you'll see that the images draw outside the image view's bounds.
Upvotes: 2