Posts

Showing posts with the label uiimageview

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

Image
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 1 Answer 1 You need to set myPicture.clipsToBounds = true ...

UIImageView disappears when aspect ratio constraint applied

Image
UIImageView disappears when aspect ratio constraint applied Xcode 9.3, MacBook Pro running OS 10.13.4 When I add an aspect ratio constraint to a UIView in IB, the view doesn't render in the simulator. Trying to find out where it went, I logged the relevant frame coordinates with the constraint absent, and then present. The coordinates appear identical, but see screenshots for difference. UIView With no constraints: self.view.center = (207.0, 368.0) self.thumbView.center = (93.0, 207.5) self.viewFinder.center = (187.5, 163.5) self.view.frame = (0.0, 0.0, 414.0, 736.0) self.thumbView.frame = (30.0, 174.0, 126.0, 67.0) self.viewFinder.frame = (16.0, 75.0, 343.0, 177.0) With only aspect ratio constraints: self.view.center = (207.0, 368.0) self.thumbView.center = (93.0, 207.5) self.viewFinder.center = (187.5, 163.5) self.view.frame = (0.0, 0.0, 414.0, 736.0) self.thumbView.frame = (30.0, 174.0, 126.0, 67.0) self.viewFinder.frame = (16.0, 75.0, 343.0, 177.0) Sure would appreciate some h...