gpt4 book ai didi

ios - UICollectionView - 在单元格之间画一条线

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

如何在跨越空间的 UICollectionView 中的单元格之间画一条线?预期的输出是这样的:

enter image description here

我所做的最好的事情是在每个单元格内添加线条。如何通过空格连接线条?

最佳答案

我做了一个扩展,你可以像这样使用:

collectionView.drawLineFrom(indexPathA, to: indexPathB, color: UIColor.greenColor())

这是扩展:

extension UICollectionView {

func drawLineFrom(
from: NSIndexPath,
to: NSIndexPath,
lineWidth: CGFloat = 2,
strokeColor: UIColor = UIColor.blueColor()
) {
guard
let fromPoint = cellForItemAtIndexPath(from)?.center,
let toPoint = cellForItemAtIndexPath(to)?.center
else {
return
}

let path = UIBezierPath()

path.moveToPoint(convertPoint(fromPoint, toView: self))
path.addLineToPoint(convertPoint(toPoint, toView: self))

let layer = CAShapeLayer()

layer.path = path.CGPath
layer.lineWidth = lineWidth
layer.strokeColor = strokeColor.CGColor

self.layer.addSublayer(layer)
}
}

结果是这样的:

A line drawn from first to second cell

关于ios - UICollectionView - 在单元格之间画一条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39396778/

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