我将文本绘制在坚实的背景色之上,当它出现时,应用于属性字符串的NSTextEffectLetterpressStyle效果不会出现--您只能看到文本颜色,而不能看到提供所需外观的附加白色轮廓。从本质上看,就像我没有应用活版效果一样。为什么,我怎样才能正确地画出活版文字效果呢?
let bitmapContext = CGBitmapContextCreate(nil, UInt(imageRect.width), UInt(imageRect.height), UInt(8), UInt(imageRect.width * 16), CGColorSpaceCreateDeviceRGB(), CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue))
CGContextSetFillColorWithColor(bitmapContext, UIColor.blackColor().CGColor)
let fullBox = CGRectMake(0, 0, imageRect.width, imageRect.height)
CGContextAddRect(bitmapContext, fullBox)
CGContextFillPath(bitmapContext)
CGContextSetTextDrawingMode(bitmapContext, kCGTextFill)
CGContextSetTextPosition(bitmapContext, drawPoint.x, drawPoint.y)
let coloredAttributedString = NSAttributedString(string: "20", attributes:[NSFontAttributeName: myFont, NSForegroundColorAttributeName: textColor, NSTextEffectAttributeName: NSTextEffectLetterpressStyle])
let displayLineTextColored = CTLineCreateWithAttributedString(coloredAttributedString)
CTLineDraw(displayLineTextColored, bitmapContext)
let cgImage = CGBitmapContextCreateImage(bitmapContext)
var myImage = CIImage(CGImage: dateStampCGImage)其结果是:

这正是我所期望的(请注意白色的大纲):

发布于 2015-05-02 11:14:32
CFAttributedString和NSAttributedString都可以将任意属性应用于范围。属性字符串类型本身并不解释属性。
相反,字符串绘制技术解释属性。核心文本理解与UIKit或AppKit不同的属性集。Core支持的属性集被记录为这里。它没有列出(相当于) NSTextEffectAttributeName。
如果使用UIGraphicsBeginImageContextWithOptions()设置当前的图形上下文,并使用NSAttributedString绘图方法将其绘制为当前图形上下文,这应该可以使用,因为它使用UIKit进行绘图。
https://stackoverflow.com/questions/28599846
复制相似问题