Uiviewcontentmodescaleaspectfill Not Clipping

UIViewContentModeScaleAspectFill not clipping

Can you try setting clip to bounds

[_photoview setClipsToBounds:YES];

Or directly in your Storyboard / Xib if you can :

Sample Image

UIImage Scale Aspect Fill and Clip Subviews not working in UICollectionView

It is very simple just do this:

imageView.contentMode = UIViewContentMode.ScaleAspectFill;
imageView.layer.masksToBounds = YES;

clipping to bounds with UIViewContentModeScaleAspectFill

The current implementation of UIViewContentModeScaleAspectFill is indeed to center the image as you pointed out, to my knowledge there's no way of altering this behavior.

UIImageView not clipping to UIView bounds while animating

As the documentation states:

Setting this value to true causes subviews to be clipped to the bounds
of the receiver.

Currently you are setting this property on cellImage ,so in this case it is the receiver, so its subviews will be clipped. But you want to clip this imageview so I think you need to set this property on cellContainerView, since you want its subviews to be clipped.

AspectFill does not fill the UIImageView

At long last, I managed to find the solution that works in Alfie's answer to this SO question.

In short, if your UIButton (or its hidden imageView) does not respond to contentMode, use this code:

self.button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
self.button.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;

UIImageView contentMode Scale Aspect Fill is Stretching the Image (Nevermind, It Wasn't)

It's not stretching it. It's filling the area while keeping the aspect ratio. If it were stretching it, the horizontal white line in the middle would not be as tall as the vertical white lines are wide.

Set the content mode to "Scale To Fill" to see what it would look like if it were getting stretched (like this):

Scale To Fill

Note the difference in line thickness of the middle white line, as opposed to when it's set to Aspect Fill:

Aspect Fill With Clip to Bounds Enabled

If you turn off Clip to Bounds on the image view, then you can see how the image is getting cropped when set to Aspect Fill:

Aspect Fill With Clip to Bounds Disabled

If you want to show the full image at the full width while keeping the aspect ratio, you'll have to increase that cell's height to accommodate the height of the image.

UIButton with the imageView set to UIViewContentModeScaleAspectFill doesn't fill completely with small images

Setting contentHorizontalAlignment and contentVerticalAlignment to .Fill on the UIButton makes it extend fully.

UIImageView clipping just some subviews

Just in case anyone else stumbles across this as I did. I found my solution to be setting clipsToBounds on the image view to FALSE:

[_myImageView addSubview:_myButton];
_myImageView.clipsToBounds = NO;

Now my button overlaps the edges of the image view.



Related Topics



Leave a reply



Submit