我正在使用ImageView和CollectionView创建一个图像库。一切正常,但肖像模式的图片超出了限制。为什么?
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
最佳答案
你需要设置
myPicture.clipsToBounds = true