下面是另一个例子:
NSString *test = [[NSString alloc] initWithFormat:@"%u:%u:%u.000", hours, minutes, seconds];
NSSize boundingSize = {100,300}; //I suppose this is the constraints?
NSRect boundingRect = [test boundingRectWithSize:boundingSize options:NULL attributes:stringAttributes];
point.x -= boundingRect.size.width; //This point points at the end of screen
[test drawAtPoint:point withAttributes:stringAttributes];
下面是stringAttributes,可以帮助菜鸟跟我一样:
NSMutableDictionary *stringAttributes;
stringAttributes = [NSMutableDictionary dictionary];
[stringAttributes setObject:[NSFont fontWithName:@"Monaco" size:16] forKey:NSFontAttributeName];
[stringAttributes setObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName];
[stringAttributes setObject:[NSColor blackColor] forKey:NSBackgroundColorAttributeName];
我想有该方法'NSAttributedString(AppKitAdditions)' 。 – zneak 2010-09-11 18:34:25
没有“像素宽度”。像素仅在光栅环境(例如窗口或位图上下文)中才有意义,并且只有在您将矢量绘制到上下文中时才会更改这些像素,例如通过绘制字符串。测量一个字符串返回其宽度(和高度)*点*。 – 2010-09-11 19:45:29