gpt4 book ai didi

ios UIImage 超出 UIImageView 边框

转载 作者:搜寻专家 更新时间:2023-11-01 05:55:03 25 4
gpt4 key购买 nike

此处黑色边框显示 UIImageView 的父 UIView,红色边框显示 UIImageView 我正在从服务器下载图像,但图像超出了 UIImageView 区域,如图所示。我正在以编程方式进行任何帮助,将不胜感激。我在下面添加代码块

enter image description here

let bottomView : UIView = UIView(frame: CGRect(x : 10, y: stackView.height, width: view.width * 0.75, height: view.width * 0.75 ))

view.addSubview(bottomView)

bottomView.layer.borderColor = UIColor.black.cgColor
bottomView.layer.borderWidth = 1

bottomView.translatesAutoresizingMaskIntoConstraints = false
bottomView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
bottomView.topAnchor.constraint(equalTo: stackView.bottomAnchor, constant: -20).isActive = true
bottomView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 10).isActive = true
bottomView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -10).isActive = true
bottomView.widthAnchor.constraint(equalToConstant: view.width * 0.75).isActive = true
bottomView.heightAnchor.constraint(equalToConstant: view.width * 0.75).isActive = true

let imageView : UIImageView = UIImageView(frame : CGRect(x: 0, y: 0, width: 250, height: 250 ))

imageView.layer.borderColor = UIColor.red.cgColor
imageView.layer.borderWidth = 1
bottomView.addSubview(imageView)

imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.centerXAnchor.constraint(equalTo: bottomView.centerXAnchor).isActive = true
imageView.centerYAnchor.constraint(equalTo: bottomView.centerYAnchor).isActive = true
imageView.widthAnchor.constraint(equalToConstant: 250).isActive = true
imageView.heightAnchor.constraint(equalToConstant: 250).isActive = true
imageView.downloadedFrom(link: (sizeResult?.results![0].data?.size_Chart?.mobile_image?.imageValue?.imageMain?.url)!, contentMode : .scaleAspectFill)

这个 bottomView 将添加 UIAlertViewController。

This image shows ** contentMode is Aspect Fit **

最佳答案

你可以使用clip绑定(bind)你的image view,绝对可以解决你的问题。 swift :

override func viewDidLoad() {
super.viewDidLoad()

self.bottomView.clipsToBounds = false
self.imageView.clipsToBounds = true
}

关于ios UIImage 超出 UIImageView 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50982423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com