我有一个 UINavigationController,它有一个 ViewController,它的 View 有一个背景图像。当我在 View 上设置这些约束时,我希望它延伸到边缘,但它似乎会延伸到左右 View 布局指南。这给我留下了我不想要的额外填充。请注意,我没有使用 Storyboard ,并且我设置了 translatesAutoresizingMaskIntoConstraints = false
以防您认为这可能会导致问题。任何有关此问题的帮助将不胜感激。
view.addSubview(backgroundImage)
backgroundImage.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
backgroundImage.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
backgroundImage.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
backgroundImage.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
最佳答案
您需要确保您在UIImageView
上设置了正确的contentMode
; .scaleAspectFill
将确保整个 ImageView 被填充,但由于保持正确的宽高比所需的剪切,您可能会丢失一些图像。
关于iOS 如何摆脱多余的 View 填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44875729/