- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
由于某些原因,我无法在使用核心文本时获取 NSTextAttachment 图像来绘制,尽管将 NSAttributedString 添加到 UILabel 时相同的图像可以正常显示。
在 iOS 上,此渲染将为 NSTextAttachment 提供空白空间,对于 OS X,将为每个 NSTextAttachment 渲染一个占位符 [OBJECT] 方形图像。为了使用 CoreText 渲染图像,是否还需要做其他事情?
渲染代码:
CGFloat contextHeight = CGBitmapContextGetHeight(context);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)_attributedString);
CGPathRef path = CGPathCreateWithRect(CGRectMake(rect.origin.x,
contextHeight - rect.origin.y - rect.size.height,
rect.size.width,
rect.size.height), NULL);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
CFRelease(framesetter);
CGPathRelease(path);
CGContextSaveGState(context);
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0.0f, contextHeight);
CGContextScaleCTM(context, 1.0f, -1.0f);
CTFrameDraw(frame, context);
CGContextRestoreGState(context);
CFRelease(frame);
最佳答案
原因很简单,NSTextAttachment 只适用于将 NSAttributedString 渲染到 UIView/NSView 中。它不能用于呈现为常规 CGContext。
有两种可能的方法来解决这个问题:
关于ios - 使用 CoreText 绘制时不显示 NSTextAttachment 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36071205/
我在触摸处理程序中有一些,它响应我在其中绘制了一些属性文本的 View 上的点击。通过这个,我已经有了一个 CTRunRef (以及相关的行)以及该运行中的字形数量。 我无法轻松弄清楚的是,如何获取该
我正在使用 CoreText 渲染多列文本。但是,当我将第一段的第一个字母设置为比文本其余部分更大的粗体字体时,我遇到了 2 个问题(均在附图中可见): 第一行下方的间距太大(我理解这是因为第一个字符
我试图按照关于 CoreText 的教程以及如何绘制文本,并在我的 customView 中实现了这个功能。 override func draw(_ rect: CGRect) {
我正在编写一个生成 PDF 的类,我会在完成后发布! 我无法将文本右对齐,使用 CTParagraphStyle,文本总是在左边。这怎么可能?我哪里错了? - (void)addText:(NSStr
我正在绘制一个文本字段,并且已将一个文本字段添加到 UIView 中。文本位于路径内。它绘制正确,但内容从底部开始到顶部结束。有办法解决这个问题吗? 这是我的代码: // Draw text into
CoreText 没有给出属性字符串的正确高度(它短了一行或更多)。我在 SO 上看到很多关于此的帖子,但无法理解或找到解决方案。有人可以解释 Core Text 高度计算的工作原理吗?这是我编写的示
我正在使用 CoreText 并且我想让我的 NSMutableAttributedString 始终居中对齐其文本。这是我正在使用的代码,但它不起作用: CTTextAlignment paragr
我正在寻找有关实现 View 的指南,该 View 在带孔的多边形内呈现 NSAttributedString,包装和重排文本以适合几何形状。这不是 CoreText 的问题,而是将不规则形状划分为有
我使用 CoreText 和 kCTJustifiedTextAlignment 在图像周围 float 一些文本以显示对齐的文本 - 但是图像更大,文本区域更小,空白更少 CoreText 不仅加宽
我在 CoreText 中注意到,在开发我自己的自定义 UITextView 以及查看 Apple 的 SimpleTextInput 时,空格或“”不会当行尾的空间用完时,它不会中断(或移动到下一行
当我实现快速滚动技术时,我正在使用 CoreText 将文本绘制到我的表格 View 单元格中。我的文本中的链接是不同的颜色并且响应点击,但我无法弄清楚如何让链接看起来像是被点击,即点击时改变颜色然后
我正在开发一款新应用。我使用 Core Text 从 NSAttributedString 呈现不同的文档。我在文本呈现中遇到奇怪的故障。并非每个文档都会发生这种情况。它何时出现与不出现似乎没有规律可
我有一个 UIView 的子类,它实现了绘制 CoreText 的代码。在应用程序中,该 UIView 绘制在 UIScrollView 内。这是我目前在 drawRect 中使用的代码:渲染 NSA
我们有一个 iOS 应用程序可以呈现大量文本:http://itunes.apple.com/br/app/biblia-sagrada/id370178518?mt=8 我们使用 CoreText
我正在尝试根据拆分成多个部分的长 NSAttributedString 动态创建书页。 我现在正在做的是将这个类别用于NSAttributedString: @interface NSAttribut
CoreText 是否有任何工具来选择字体的 SmallCaps 变体,或者在字体没有该功能的情况下合成小型大写字母?我在 CoreText 文档中找不到任何关于小型大写字母的内容,尽管有处理字体变化
我使用 CoreText 显示一些文本,创建框架 setter 、框架等,一切都很好。我什至可以格式化文本,但这一切都是在绘制之前完成的。现在让我发疯的问题是: CoreText只是渲染文本?我无法获
我正在尝试使用各种技术获取 MacOS X/iOS 中角色的边界框。我现在展示我所有的尝试。到目前为止,如果我想获取变音符号(例如“Ä”)的大小,代码会失败。 使用CTFontGetBoundingR
我正在尝试使用 CoreText api 呈现字符串。每个字符都在 CAShapeLayer 中呈现,我正在为每个字符获取图层偏移(x 坐标),如下所示: let offset = CTLineGet
我正在使用 CoreText 在灰色背景上绘制黑色文本。系统似乎会自动对字形进行一些混合,我想尽可能禁用此行为,但我不确定如何禁用。 这是字母 L 顶部的放大截图。这是我要禁用的混合 绘图代码如下:
我是一名优秀的程序员,十分优秀!