问题标签 [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.
cocoa - 如何获得 NSButton 的首选大小?
我有一个NSMenuItem
包含NSButton
. 按钮的标题是在运行时确定的,我想调整按钮的框架,以便内容(按钮标题)始终适合。
我知道[NSAttributedString boundingRectWithSize:options:]
,但我想知道是否有内置方法可以为 NSButtons 甚至在 NSView 级别执行此操作。
iphone - 如何设置HighlightedTextColor @ NSAttributedString
我有一个使用 NSAttributedString 的自定义 UITableViewCell。我希望它在选择单元格时改变颜色。如何使 NSAttributedString 具有与设置了 highlightTextColor 的 UILabel 相同的行为?
我试图在单元格的 setSelected 和 setHighlighted 函数中更改颜色,但似乎它们被调用到较晚(在 touchUpInside 而不是 touchDown 上)
提前致谢!
ios - 在没有 UIWebView 的 iOS 设备上显示 .RTF 文件 - iOS 上的 initWithRTF?
可以使用 a 在 iOS 中呈现.RTF
文件UIWebView
(请参见此处)。如何直接将 .RTF 文件“渲染”到自定义层,而不依赖于UIWebView
?
我正在显示一个带有自定义的表格视图UITableViewCell
。该单元格具有以下格式:
RTF 内容直接来自应用程序附带的一系列文件。从历史上看,我可以将 RTF 转换为 HTML 并使用UIWebView
. 随着越来越多的用户内容和在移动和桌面用户之间共享内容的附加功能,首选的文件格式是.RTF
.
在 MacOS 上,您可以使用(id)initWithRTF:(NSData *)data documentAttributes:(NSDictionary **)dict
创建一个 NSAttributedString
. iOS上的等价物是什么?甚至可能吗?
iphone - CTLine 或 NSAttributedString——在没有图形上下文的情况下获取图像边界?
这可能吗?基本上,我有一堆 NSAttributedString 对象和相应的 CTLine 对象。我想在 drawRect 阶段之前获得图像边界。所以在这一点上,没有什么可以借鉴的。然后,我将使用这些图像边界来确定我需要为绘图创建什么。
编辑:尺寸的另一种测量可能会很好。但是调用具有欺骗性名称的 CTLineGetTypographicBounds 函数只返回宽度。如果我传入上升和下降浮动的地址,它们会返回为零。
编辑:给定的答案在 MacOS 中效果很好。任何人都可以在 iOS 中做到这一点吗?
ios - 将带有 NSAttributed 字符串的字典保存到 PList 或 NSUserDefaults
我有一个字典NSAttributtedString
我尝试将此字典另存为 Documents 文件夹中的 Plist,并将字典保存在NSUserDefaults
. 两者都不起作用。如果字典中的属性字符串被删除,这两种方法都有效。
用于保存到 Documents 文件夹中 Plist 的代码:
用于保存字典的代码NSUserDefaults
:
有人请帮忙。我错过了什么吗?
cocoa - 可以为 NSTextField 设置对齐方式或字体,但不能同时设置两者
我有一个面板笔尖,它的一个文本字段有一个出口,它在笔尖中设置为居中对齐。当我显示面板时,我希望这个文本字段加粗。由于 NSTextField 是 NSControl 的子类,它可以使用 setAttributedStringValue 方法并获取属性字符串。所以我加入了这样的粗体字体:
粗体显示正常,但该字段现在左对齐。
我尝试添加一个 setAlignment,但它没有效果:
所以我尝试在属性字符串的属性中添加一个居中的段落样式:
现在文本字段再次居中,但粗体消失了。就好像属性字符串可以接受一个且只有一个属性设置。我错过了一些简单的东西吗?
nsattributedstring - 核心文本 - NSAttributedString 行高做对了吗?
我对 Core Text 的行距一无所知。我正在使用 NSAttributedString 并在其上指定以下属性: - kCTFontAttributeName - kCTParagraphStyleAttributeName
由此创建 CTFrameSetter 并将其绘制到上下文中。
在段落样式属性中,我想指定行的高度。
当我使用 kCTParagraphStyleSpecifierLineHeightMultiple 时,每行都会在文本顶部接收填充,而不是在此高度的中间显示文本。
当我使用 kCTParagraphStyleSpecifierLineSpacing 时,会在文本底部添加一个填充。
请帮助我使用位于该高度中间的文本(字形)来实现指定的行高,而不是位于行底部或顶部的文本。
如果不遵循明确创建 CTLine 等的路线,这是不可能的吗?
ipad - 在 NSAttributedString - ipad 上设置文本对齐 (CTTextAligment)
我正在尝试使用颜色、字体、大小和对齐方式绘制自定义字符串。
我之前使用 NSMutableAttributedString 进行了所有工作,但看起来文本对齐仅适用于段落对齐,它仅适用于非可变版本的 NSString。
所以,我不得不将我以前的代码更改为:
但是文本对齐仍然不起作用。其他一切都很好,但文本保持在左侧对齐。
为什么 ?
EDIT :
Each of my strings are created inside a class that is a subclass of CATextLayer. Each of those TextLayers are then added to a CALayer as sublayers. On updates I apply trasformation matrix on the sublayers and use setNeedsDisplay
. This is how I display the text on screen. Maybe There's a reason here why the CTParagraphStyleRef set is not working ?
ios - NSAttributedString 指定范围?
使用时是否可以指定范围-[NSAttributedString initWithString:attributes:]
?
我知道我可以NSMutableAttributedString
使用NSAttributedString
.
string - 用另一个 NSAttributedString 替换 NSAttributedString 的子字符串
我想用另一个替换一个子字符串(例如@"replace"
)。NSAttributedString
NSAttributedString
我正在寻找与NSString
's stringByReplacingOccurrencesOfString:withString:
for等效的方法NSAttributedString
。