【发布时间】:2015-12-04 22:12:24
【问题描述】:
我想将我的 CATextLayer 与 UIImage 合并为一个 UIImage。我正在使用此代码:
let textViewLayer = CATextLayer()
textViewLayer.frame = CGRect(origin: CGPoint(x: lockText.imagePositionX, y: lockText.imagePositionY), size: lockImageView.frame.size)
textViewLayer.string = lockText.textText
textViewLayer.font = lockText.textFont.fontName
textViewLayer.fontSize = lockText.textFontSize
textViewLayer.foregroundColor = lockText.color.CGColor
let textView = UIView(frame: lockImageView.frame)
textView.layer.addSublayer(textViewLayer)
lockImageView.addSubview(textView)
UIGraphicsBeginImageContext(lockImageView.frame.size)
textViewLayer.renderInContext(UIGraphicsGetCurrentContext()!)
image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
但是 UIGraphicsGetCurrentContext 是 NIL。谁能告诉我,我做错了什么?
【问题讨论】:
-
你为什么不改用
NString.drawInRect:withAttributes呢?例如,您不需要创建文本层来组合带有文本水印的图像。
标签: ios uiimage calayer uigraphicscontext