场景:
1. 自定义view或其他控件时, 往往需要根据背景色或图片绘制特定颜色的文本.
NSMutableDictionary* stringAttributes = [NSMutableDictionary dictionaryWithCapacity:1];
//[stringAttributes setObject:[NSFont messageFontOfSize:12.0] forKey:NSFontAttributeName];
[stringAttributes setObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName];
NSString* systemCapacity = [NSString stringWithFormat:@"System: %@",[FileUtil ZLGetFormatSizeFromBytes:system]];
NSSize systemSize = [systemCapacity sizeWithAttributes:stringAttributes];
theRect1.origin.x += (theRect1.size.width - systemSize.width)/2;
[systemCapacity drawAtPoint:theRect1.origin withAttributes:stringAttributes];
效果图