gpt4 book ai didi

ios - 如何剪切图像的角

转载 作者:行者123 更新时间:2023-11-28 06:16:28 24 4
gpt4 key购买 nike


我用一个 swift 文件制作这个 View

import UIKit

@IBDesignable class DesignView: UIView {

@IBInspectable var CornerRadius: CGFloat = 0 {
didSet {
self.layer.cornerRadius = CornerRadius
}
}

}

但是当我设置图像背景时, View 的图像溢出是这样的:

我尝试像这样将相同的 swift 文件应用到我的 ImageView

import UIKit

@IBDesignable class DesignImageView: UIImageView {

@IBInspectable var CornerRadius: CGFloat = 0 {
didSet {
self.layer.cornerRadius = CornerRadius
}
}

}

但是没有任何附加内容,所以我如何在不编辑图像的情况下偷工减料?

最佳答案

尝试

view.clipsToBound = true

您的图片由于其尺寸超出了边界

来自 Apple Developer Docs :

Setting this value to true causes subviews to be clipped to the bounds of the receiver. If set to false, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value is false.

关于ios - 如何剪切图像的角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44994668/

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