UIViewContentModeScaleAspectFill not clipping
Can you try setting clip to bounds
[_photoview setClipsToBounds:YES];
Or directly in your Storyboard / Xib if you can :
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):
Note the difference in line thickness of the middle white line, as opposed to when it's set to Aspect Fill:
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:
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
Storyboard View Elements Greyed Out
How to Use Core Location/Gps Without Any Internet Connection/Disabled Cellular Network
Nsxmlparser: Unexpected Result with Non-Ascii Characters
Libraries Not Found When Using Cocoapods with iOS Logic Tests
Using Custom Font in a Uiwebview
Enterprise In-House App Distribution
Missing Cfbundleiconname in Xcode9 iOS11 App Release
What Does the Text Inside Parentheses in @Interface and @Implementation Directives Mean
Swift 2.0 Sorting Array of Objects by Property
Swift 4 "This Class Is Not Key Value Coding Compliant"
iOS - How to Play a Video with Transparency
iOS 9 Segue Causes App to Freeze (No Crash or Error Thrown)
Auto Login Dropbox Account on Core API Without Login Prompt
Difference Between _ and Self. in Objective-C
Implementing Google Custom Search API in iOS