gpt4 book ai didi

ios - CGPattern 与 swift

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

我想用

func CGContextSetFillPattern(_ c: CGContext!,
_ pattern: CGPattern!,
_ components: UnsafePointer<CGFloat>)

在我的绘图应用程序中,填充图案......我如何使用 swift 实现 CGPattern ?CGContext 引用 link

 func drawLineFrom(fromPoint: CGPoint, toPoint: CGPoint) {

// 1
UIGraphicsBeginImageContext(view.frame.size)
let context = UIGraphicsGetCurrentContext()
tempImageView.image?.drawInRect(CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height))

// 2
CGContextMoveToPoint(context, fromPoint.x, fromPoint.y)
CGContextAddLineToPoint(context, toPoint.x, toPoint.y)

// 3
CGContextSetLineCap(context, kCGLineCapRound)
CGContextSetLineWidth(context, brushWidth)
CGContextSetRGBStrokeColor(context, red, green, blue, 1.0)
CGContextSetBlendMode(context, kCGBlendModeNormal)

// 4
CGContextStrokePath(context)

// 5
tempImageView.image = UIGraphicsGetImageFromCurrentImageContext()
tempImageView.alpha = opacity
UIGraphicsEndImageContext()

最佳答案

您可以查看此链接 Quartz 2D programming PatternsCGPattern .在使用 fillpatern 的快捷方式中,您需要编写一个回调函数来绘制一个 pattern 实例,然后将回调指针传递给 cgpatterncreate。

这里有如何在 obj-c 中制作它的教程 cgpatternref obj-c你可以轻松地将它翻译成 swift

关于ios - CGPattern 与 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29576023/

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