- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用
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 Patterns和 CGPattern .在使用 fillpatern 的快捷方式中,您需要编写一个回调函数来绘制一个 pattern 实例,然后将回调指针传递给 cgpatterncreate。
这里有如何在 obj-c 中制作它的教程 cgpatternref obj-c你可以轻松地将它翻译成 swift
关于ios - CGPattern 与 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29576023/
我有一个简单的代码在 UIView 上绘制大小为 PSIZE = 50 的方形图案。当我从零(0,0)点开始绘制时,一切都很好。当我将上下文转换为另一个点而不是 PSIZE 的倍数时,该模式仍然有效但
我想使用我拥有的 .png 绘制路径,但我只是不知道如何制作 CGPatternRef。 最佳答案 这是一个小片段 - (void)drawRect:(CGRect)rect { CGCont
我想用 func CGContextSetFillPattern(_ c: CGContext!, _ pattern: CGPattern!,
我设置了一个图层,如下所示: CALayer *layer = [CALayer layer]; layer = /* create a CGColorRef with a pattern image
我正在尝试使用 CGPattern 创建彩色图案在 swift 。 Apple 在 Quartz 2D Programming Guide 中提供了一个很好的 Objective-C 示例在他们关于
背景 在 iOS6 中,我过去常常在 MKMapView 上添加几个 MKPolygon(叠加层),并为 mapView:viewForOverlay: 提供特定的 MKOverlayView: >
我是一名优秀的程序员,十分优秀!