问题标签 [nsattributedstring]

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 回答
1079 浏览

cocoa - 在 NSMatrix 中的 NSButtonCell 中的文本之前显示图像

我在 NSMatrix 中显示按钮。

我的要求是:

当满足特定条件时,更改按钮标题的颜色并将图像放置在标题的开头。

为此,我使用了以下代码:

尽管上面的代码显示了标题颜色的变化,但它没有显示标题开头的图像:(

任何人都可以建议我在哪里可能出错或其他一些方法来实现我的要求吗?

编辑:

在线:

它在编译时给出这个警告:

谢谢,

米拉杰

0 投票
15 回答
159099 浏览

ios - 单个 UILabel 中的粗体和非粗体文本?

如何在 uiLabel 中同时包含粗体和非粗体文本?

我宁愿不使用 UIWebView .. 我也读过这可能使用 NSAttributedString 但我不知道如何使用它。有任何想法吗?

苹果在他们的几个应用程序中实现了这一点;示例截图:链接文本

谢谢!- 多姆

0 投票
2 回答
2142 浏览

objective-c - 如何正确确定属性字符串的宽度

我想要做的:使用 NSLayoutManager 布局文本并将其 NSTextContainer 设置为字符串数组中最宽字符串(字形)的宽度。

我的问题是:确定总“字形宽度”的方法似乎不正确,因为当我渲染文本时它会换行。

我做了一个实验,使用 32 个字符串和 Monaco 12 点字体,长度报告为 224.0,但如果长度设置为 234.0,文本只会停止换行。

这段代码演示了我上面所说的内容,并在计算的字形宽度的右侧显示了一条垂直线。

0 投票
4 回答
12677 浏览

iphone - 如何在 iPhone 上显示 NSAttributedString?

我相信我了解如何设置 NSAttributedString 值,但是您到底如何在界面中实际显示它们?

示例:UILabel、UITextView 等。

将不胜感激具体说明/

  • 谢谢!
0 投票
2 回答
6307 浏览

iphone - iPhone中的NSForegroundColorAttributeName键

我听说在 iPhone 中添加了 NSAttributedString,但是当我使用键 NSForegroundColorAttributeName 设置颜色时,我收到一条错误消息,提示“NSForegroundColorAttributeName undeclared”。我错过了什么吗?请帮我。

问候

亚拉帕

0 投票
3 回答
4447 浏览

iphone - 如何清除 NSMutableAttributedString 的内容?

我有一个在对象的 init 中分配初始化的 ivar:

在循环中,我想清除 attString 的内容并重新使用它。我该怎么做呢?

谢谢!

0 投票
9 回答
93273 浏览

iphone - iphone/ipad:究竟如何使用 NSAttributedString?

是的,很多人都在谈论 iPhone/iPad 中的富文本,而且很多人都知道NSAttributedString.

但是怎么用NSAttributedString?我搜索了很多时间,没有提取线索。

我知道如何设置NSAttributedString,那么我应该怎么做才能在 iPhone/iPad 上显示带有富文本的文本?

官方文档说它应该与 一起使用CoreText.Framework,这是什么意思?

有没有这样简单的方法?

0 投票
4 回答
4084 浏览

iphone - iPhone CoreText:查找子字符串的像素坐标

这是 twitter 应用程序的截图供参考:http ://screencast.com/t/YmFmYmI4M

我想要做的是在可以跨越多行的 NSAttributedString 中的子字符串顶部放置一个浮动弹出窗口。NSAttributedString 是项目的要求。

在提供的屏幕截图中,您可以看到链接是背景突出显示的,因此我相信它们使用的是 CoreText 和 NSAttributedStrings。我还发现了一个名为 CTRunRef ( http://developer.apple.com/library/ios/#documentation/Carbon/Reference/CTRunRef/Reference/reference.html ) 的东西,看起来很有希望,但我无法将它们全部组合在一起概念上。

简而言之,如果我在核心文本中有一个段落,当我点击一个单词时,我如何找到该单词的边界框?

0 投票
8 回答
4852 浏览

objective-c - 如何使用核心文本和属性字符串伪造上标和下标?

我正在使用一个NSMutableAttribtuedString来构建一个带格式的字符串,然后我将它传递给 Core Text 以呈现到一个框架中。问题是,我需要使用上标和下标。除非这些字符在字体中可用(大多数字体不支持它),否则设置属性kCTSuperscriptAttributeName根本不会做任何事情。

所以我想我只有唯一的选择,那就是通过改变字体大小和移动基线来伪造它。我可以做字体大小位,但不知道更改基线的代码。有人可以帮忙吗?

谢谢!

编辑:我正在考虑,考虑到我有多少时间可以对这个问题进行排序,编辑字体以便给它一个下标“2”......或者找到一个内置的 iPad 字体。有谁知道我可以使用任何带有下标“2”的衬线字体?

0 投票
1 回答
1053 浏览

objective-c - reading binary data (rtf) to string

I've been working on a core data program for a while now. I'm trying to combine attributes of an entity in a text view for saving to PDF and Printing. One of the attributes of the entity uses binary data.

When I execute this:

NSData *myData = [object valueForKey:@"cueNotes"];

...it returns this:

when I try this:

... myDataTry is nil. I read a little about the rtf format and then removed this:

...from the myData data but still get a nil result. Does anyone have any idea what I'm doing wrong?

Update: After thinking about the first answer I tried this (as well as a couple permutations):

as well as an allocated string and still no results.

Here is the results of the entity that I'm pulling from:

})