代码之家  ›  专栏  ›  技术社区  ›  Tigran

为什么uiimageview的内容模式是.scalespectfill在纵向图片中超出了它的限制?

  •  0
  • Tigran  · 技术社区  · 7 年前

    我正在使用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
    

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  1
  •   Shehata Gamal    7 年前

    你需要设置

    myPicture.clipsToBounds = true