gpt4 book ai didi

ios - 制作自定义形状 imageview ios swift 4.2

转载 作者:可可西里 更新时间:2023-11-01 01:07:51 25 4
gpt4 key购买 nike

我是 ios 的新手。我正在尝试将 ImageView 的底部边框(不是整个底部的左侧或右侧)制作成曲线。任何人都可以指导我如何去做。

Here is the image of the border i want to acheive:

enter image description here

最佳答案

你可以这样做:

func curvedShapeFor(view: UIImageView, curvedPercent:CGFloat) ->UIBezierPath
{
let path = UIBezierPath()
path.move(to: CGPoint(x:0, y:0))
path.addLine(to: CGPoint(x:view.bounds.size.width, y:0))
path.addLine(to: CGPoint(x:view.bounds.size.width, y:view.bounds.size.height - (view.bounds.size.height*curvedPercent)))
path.addQuadCurve(to: CGPoint(x:0, y:view.bounds.size.height - (view.bounds.size.height*curvedPercent)), controlPoint: CGPoint(x:view.bounds.size.width/2, y:view.bounds.size.height))
path.addLine(to: CGPoint(x:0, y:0))
path.close()

return path
}

然后像这样申请:

let shapeLayer = CAShapeLayer(layer: imageView.layer)
shapeLayer.path = self.curvedShapeFor(view: imageView,curvedPercent: 0.6).cgPath
shapeLayer.frame = imageView.bounds
shapeLayer.masksToBounds = true
imageView.layer.mask = shapeLayer

关于ios - 制作自定义形状 imageview ios swift 4.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54036965/

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