gpt4 book ai didi

ios - 如何使用 Swift 仅对图像的某些角进行圆角处理

转载 作者:行者123 更新时间:2023-11-28 10:18:33 25 4
gpt4 key购买 nike

我只想将图像的两个底角圆化。我在 Objective-C 中找到了很多示例,而在 Swift 中几乎找不到任何示例。

这是我发现的,但它给了我一个错误:

let rectShape = CAShapeLayer()

rectShape.bounds = self.image.frame
rectShape.position = self.image.center
rectShape.path = UIBezierPath(roundedRect: self.image.bounds, byRoundingCorners: .BottomLeft | .BottomRight, cornerRadii: CGSize(width: 20, height: 20)).CGPath

self.image.layer.backgroundColor = UIColor.greenColor().CGColor

self.image.layer.mask = rectShape

我得到的错误与 rectShape.path 一致,并告诉我

No '|' candidates produce the expected contextual result type 'UIRectCorner'

最佳答案

swift 改变了我们放置这些东西的方式。在 objective-c 中可以写一个 |分开选项,但很快你必须把它像一个数组一样:

let rectShape = CAShapeLayer()

rectShape.bounds = self.image.frame
rectShape.position = self.image.center
rectShape.path = UIBezierPath(roundedRect: self.image.bounds, byRoundingCorners: [.BottomLeft, .BottomRight], cornerRadii: CGSize(width: 20, height: 20)).CGPath

self.image.layer.backgroundColor = UIColor.greenColor().CGColor

self.image.layer.mask = rectShape

关于ios - 如何使用 Swift 仅对图像的某些角进行圆角处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37985924/

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