Answer the question
In order to leave comments, you need to log in
Shadow + cornerRadius + scaleAspectFit in imageView?
Greetings
Guys, who came across, it is necessary to implement in UIImageView
- rounding corners and shadow
1. Implementation is required in mode UIImageView.contentMode = .scaleAspectFit
2. UIImageView
You can add it as a subview in UIView
, but then how to transfer it to the view frame imageView? If set view.frame = imageView.frame
, it does not work
3. Who has a solution for all these three aspects?
Answer the question
In order to leave comments, you need to log in
To make the frame of the UIImageView match the size of the image, you need to get the dimensions of the UIImage . In practice, get the aspect ratio of the UIImage , and resize the frame with that aspect ratio.
Now the picture will always fit into the frame.
Think it makes sense to fit the frame to the image, not the image to the frame, if you use .scaleAspectFit .
Rounding the corners
Now that the frame has the same dimensions as the image, rounding the corners will work correctly. Problem solved.
Shadows
Depends on the method. If you activate the mask, then the shadow will not be visible . Make a container in which you putUIImageView , put a mask for it. And we put a shadow on the container.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question