Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure what the issue is - ensure your <code>UIImageView</code>'s <code>clipsToBounds</code> property is set to <code>NO</code>. You can do this in <code>viewDidLoad</code> after loading from the nib file by referencing your IBOutlet. You shouldn't need to wrap it in another view. <br> <br> <strong>Edit</strong></p> <p>In light of you needing your image to be scaled using aspect fill, you can use the <code>contentsRect</code> property of the <code>UIImageView</code>'s underlying layer to 'simulate' the effect of the contents clipping. <code>contentsRect</code> is rectangle in the unit coordinate space of the layer's content (in this case your image) that defines a sub-rectangle of the contents that should be drawn.</p> <p>With a little bit of maths, we can find this rectangle by comparing the image view size with the image size (accounting for the aspect fill scaling):</p> <pre><code>CGSize imageViewSize = previewImage.size; CGSize imageSize = previewImage.image.size; // Find the scaling required for the image to fit the image view (as for aspect fill). CGFloat imageWidthScale = fabsf(imageViewSize.width / imageSize.width); CGFloat imageHeightScale = fabsf(imageViewSize.height / imageSize.height); CGFloat imageScale = (imageWidthScale &gt; imageHeightScale) ? imageWidthScale : imageHeightScale; // Determine the new image size, after scaling. CGSize scaledImageSize = CGSizeApplyAffineTransform(imageSize, CGAffineTransformMakeScale(imageScale, imageScale)); // Set the layer's contentsRect property in order to 'clip' the image to the image view's bounds. previewImage.layer.contentsRect = CGRectMake(((scaledImageSize.width - imageViewSize.width) / 2.0f) / scaledImageSize.width, ((scaledImageSize.height - imageViewSize.height) / 2.0f) / scaledImageSize.height, imageViewSize.width / scaledImageSize.width, imageViewSize.height / scaledImageSize.height); </code></pre> <p>Doing this, you can leave <code>clipsToBounds</code> set to <code>NO</code> for your image view, but the image will still appear clipped. If you need to change the image view size at all, it might be convenient to wrap this code up into a method that takes a <code>UIImageView</code> as a parameter.</p> <p>I hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload