Why UIImageView when its content mode is .scaleAspectFill in portrait pictures goes over its constraints?


Why UIImageView when its content mode is .scaleAspectFill in portrait pictures goes over its constraints?



I'm creating an image gallery using ImageView and CollectionView. Everything is working fine but portrait mode pictures go over constraints. Why is that?


myPicture = UIImageView(image: myArray[0])
view.addSubview(myPicture)
myPicture.translatesAutoresizingMaskIntoConstraints = false
myPicture.contentMode = .scaleAspectFill
myPicture.topAnchor.constraint(equalTo: tabBar.bottomAnchor, constant: view.bounds.height / 80).isActive = true
myPicture.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0).isActive = true
myPicture.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0).isActive = true
myPicture.bottomAnchor.constraint(equalTo: collectionView.topAnchor, constant: 0).isActive = true



enter image description here




1 Answer
1



You need to set


myPicture.clipsToBounds = true





o my gosh, so stupid, thank you very much
– Tigran
Jul 1 at 2:00






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

List of Kim Possible characters

Python Tkinter Error, “Too Early to Create Image”