我正在尝试创建一个在 UI 视图中具有用户图像的个人资料页面。但是,当我加载图像时,它不会填充我创建的圆形 UI 视图。
代码如下:
profileImageView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
profileImageView.anchor(left: view.leftAnchor, paddingLeft: 32, width: 120, height: 120)
profileImageView.layer.cornerRadius = 120 / 2
profileImageView.layer.borderWidth = 1.0
profileImageView.contentMode = .scaleAspectFit
profileImageView.layer.masksToBounds = true
profileImageView.layer.borderColor = UIColor.white.cgColor
profileImageView.clipsToBounds = true
当我用图像填充 profileImageView.image 时,结果是这样的:
我想让它填满整个空间。谁能帮忙?
看起来您在构建此图像时正在使用
scaleAspectFit
,这将调整整个图像的大小以适应您设置的宽度或高度。如果你想填充它,我会尝试scaleAspectFill
。它可能会在侧面剪裁图像,但它应该按照您的意图填充整个空间。