问题
I'm using drawGlyphsForGlyphRange
to render an NSAttributedString
(in NSView
drawRect
)
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!!
Thanks
回答1:
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.
来源:https://stackoverflow.com/questions/13029222/nsattributedstring-default-color-font-etc