问题标签 [nstextattachment]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
5187 浏览

ios - 在 UILabel 中,是否可以强制一条线不在某个地方中断

我有一个应该有两行长的 UILabel。文本已本地化为法语和英语。

我正在设置标签的属性文本属性。文本由三个附加字符串构成,例如 textFragment1、textFragment2 和 textFragment3。中间的字符串实际上是使用 NSTextAttachment 创建的图像。

我想确保 textFragment2 和 textFragment3 在同一行。第一个字符串可能会或可能不会换行,具体取决于它的长度。问题是我的法语文本目前相当短,所以该行在 textFragment2 之后换行。

我已通过在 textFragment1 的本地化法语文本中添加换行符来临时解决此问题。不过,我真的不喜欢这个解决方案。我想知道是否有一种方法可以处理 textFragment2 和 textFragment3 以便它们始终在同一行上。

0 投票
2 回答
2237 浏览

ios - NSTextAttachment 图像未显示在 iOS 8 设备上(使用 iOS7.1 sdk)

我刚刚在几台 iOS 8 设备上构建了我的项目,baseSDK 设置为 iOS 7.1。不幸的是,所有作为属性添加到 NSMutableAttributedString 相关实例的 NSTextAttachment 图像在 iOS 8 设备和 iOS 8 模拟器上都是隐藏的(它们在 7.1 和 iOS 7.1 模拟器的设备上仍然可见)。这些字符串在它们的父视图中的框架被设置为好像图像在那里,但图像本身只是不可见或不渲染。

有没有其他人遇到过 iOS 8 上没有出现文本附件的问题。如果是这样,是否有解决方法?如果没有,我的代码是否有问题(粘贴在下面)?这个实例特别为 UIButton 设置了一个属性标题,但我还有其他带有附件的实例,这些附件是显示相同行为的简单 UILabel。

注意:如果可以的话,我会发布图片来说明,但我没有这样做的最低堆栈溢出声誉。

0 投票
10 回答
46967 浏览

ios - 在单行 UILabel 旁边居中 NSTextAttachment 图像

我想将NSTextAttachment图像附加到我的属性字符串并使其垂直居中。

我使用以下代码来创建我的字符串:

但是,图像似乎与单元格的顶部对齐textLabel

文字附件偏移问题截图

如何更改绘制附件的矩形?

0 投票
1 回答
403 浏览

ios - NSTextAttachment 字距调整

我正在尝试更改 UITextView 中 NSTextAttachment 图像的水平位置。我试过设置

这只会使附件消失,同时给我适当的字距调整空间。我也试过改变原点x坐标

这对附件的水平位置没有影响。请指教。

0 投票
4 回答
27858 浏览

swift - How do I insert an image Inline UILabel in iOS 8 using swift

I followed the following post on how to use NSTextAttachment to add images inline with your UILabels. I followed the best I could and wrote my version in Swift.

I am creating a chat application and the field that I'm inserting a beer icon into does not render the image or doesn't seem to render the image inline. I don't get any errors so I'm assuming I'm missing some small little detail in my code.

0 投票
3 回答
7057 浏览

ios - NSTextAttachment 图像对齐

我正在关注@Duncan Groenewald 编写的在 OS X 和 iOS 上使用图像实现富文本的UITextView酷教程,并且能够在我的. 然而,这些图像并没有像我希望的那样居中。看图片

NSTextAttachment 示例图片

如您所见,我希望我的图像以 X 轴为中心。

我尝试rect用适当的值返回,-attachmentBoundsForTextContainer:proposedLineFragment:glyphPosition:characterIndex但这没有帮助。

我还尝试NSKernAttributeNameNSTextAttachment属性字符串设置。但它所做的只是以某种方式隐藏图像。

0 投票
1 回答
318 浏览

swift - 在 Swift 中从 NSTextField 获取 NSImage

我曾经从 Obj-C 检索 NSTextField 子类中的 NSImage,如下所示:

当我尝试在 Swift 中做同样的事情时,我似乎无法转换attachmentCell但得到一个编译器错误:

0 投票
1 回答
245 浏览

ios - 如何修改 NSTextAttachement 在 uilabel 中的位置?

如图所示,我在一个标签中有两个图像 NSTextAttachments,标签的背景颜色为红色,如果我想在标签中将图像向下移动一点,如何实现?

在此处输入图像描述

(上面的图像底部被截断,因为它是空白)。

0 投票
1 回答
215 浏览

ios - NSAttributeString Height seems align wrong when use both image and text

I have a uilabel in tableviewcell ,and the label use NSAttributeString to support both image and text. But I found when the label contains image or text only , the height of label is correct ,but when label contains image and text both ,the height seems not correct .the row height seems little more big than the actual height need

enter image description here

and if there is text or images only ,the height is right

enter image description here

and I was using my Own subclass from NSTextAttachment to construct image enter image description here

and the attachment code is like this enter image description here

0 投票
1 回答
498 浏览

ios - 如何获取包含 UIImage 的 NSAttributedString 的自定义文本等效项?

我有一个聊天应用程序,我需要在其中发送图像(表情符号)和文本。
现在,我可以通过NSTextAttachment(下面的代码)添加图像

现在,我想要的是:)在微笑图标上附加一个自定义文本说“”,以便在调用时_txtChat.text返回:) 而不是UIImage. 所以,如果用户看到Hii <Smilie>,我会得到"Hii :)"。我无法确定是否有可能获得。