NSAttributedString default color/font etc

风格不统一 提交于 2019-12-07 08:34:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!