0

我在纯色背景颜色上绘制文本,当它出现时,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)

这是结果:
在此处输入图像描述

这就是我所期望的(注意白色的轮廓):
在此处输入图像描述

4

1 回答 1

0

两者都CFAttributedString可以NSAttributedString将任意属性应用于范围。属性字符串类型本身并不解释属性。

相反,字符串绘制技术解释属性。Core Text 理解一组不同于 UIKit 或 AppKit 的属性。Core Text 支持的属性集在此处记录。它没有列出(等价于)NSTextEffectAttributeName

如果您使用绘图方法设置当前图形上下文UIGraphicsBeginImageContextWithOptions()并绘制到该上下文中NSAttributedString,那应该可以工作,因为它使用 UIKit 进行绘图。

于 2015-05-02T11:14:32.533 回答