NSAttributedString 默认颜色/字体等 [英] NSAttributedString default color/font etc

查看:52
本文介绍了NSAttributedString 默认颜色/字体等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 drawGlyphsForGlyphRange 来渲染一个 NSAttributedString(在 NSView drawRect 中)

I'm using drawGlyphsForGlyphRange to render an NSAttributedString (in NSView drawRect)

有没有办法默认 NSAttributedString 的颜色/字体等?显然,我可以专门为给定范围设置这些值 - 但这将覆盖字符串中的任何特定设置.感觉我对 NSAttributedStrings 应该如何使用有一个根本的误解!!

Is there any way to default the color/font etc of an NSAttributedString? Clearly I could set those values specifically for a given range - but that will then override any specific settings in the string. Got the feeling I have a fundamental misunderstanding of how NSAttributedStrings should be used!!

谢谢

推荐答案

NSAttributedString 对象的默认字体在 iOS 上是 Helvetica 12-point,在 OS X 上是 Lucida Grande(或任何设置的默认系统字体).使用 initWithString:attributes: 创建一个带有一些预设属性的 NSAttributedString,这些属性最初会应用于整个字符串.之后您将设置为字符串的不同范围的任何属性都将补充/替换您在创建 NSAttributedString 实例时定义的属性.

The default font for NSAttributedString objects is Helvetica 12-point on iOS and Lucida Grande (or whatever the default system font is set to) on OS X. Use initWithString:attributes: to create an NSAttributedString with some pre-set attributes that would initially apply to the whole string. Any attributes you will set to different ranges of your string afterwards will supplement/replace the attributes you define when you create your instance of NSAttributedString.

这篇关于NSAttributedString 默认颜色/字体等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆