如何使用`prepare(_ context: CGContext, with rendererContext: UIGraphicsRendererContext)`?

Posted

技术标签:

【中文标题】如何使用`prepare(_ context: CGContext, with rendererContext: UIGraphicsRendererContext)`?【英文标题】:How to use `prepare(_ context: CGContext, with rendererContext: UIGraphicsRendererContext)`? 【发布时间】:2017-08-08 06:04:54 【问题描述】:

ios 10 开始,Apple 在 UIKit 中记录了这个类函数:

class func prepare(_ context: CGContext, with rendererContext: UIGraphicsRendererContext)

但是,我无法在 Xcode 8.3.3 中访问 prepare

// error: Type 'UIGraphicsRenderer' has no member 'prepare'
UIGraphicsRenderer.prepare(UIGraphicsGetCurrentContext()!, with: UIGraphicsRendererContext())

// error: Type 'UIGraphicsImageRenderer' has no member 'prepare'
UIGraphicsImageRenderer.prepare(UIGraphicsGetCurrentContext()!, with: UIGraphicsRendererContext())

【问题讨论】:

你要导入import UIKit.UIGraphicsRendererSubclass,方法在这个类中定义。 不客气,很高兴我能帮上忙 :) 【参考方案1】:

函数prepare定义在UIGraphicsRendererSubclass 你可以通过callingimport UIKit.UIGraphicsRendererSubclass导入这个类

【讨论】:

以上是关于如何使用`prepare(_ context: CGContext, with rendererContext: UIGraphicsRendererContext)`?的主要内容,如果未能解决你的问题,请参考以下文章