I am using the DrawRect method to draw some text and can’t figure out how to align this text to the right.
I know in interface builder you can specify the alignment so I know it is possible, I just can’t seem to figure it out my self.
Any help at this point is extremely helpful.
Thanks so much!
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"AvenirNext-UltraLight" size:12], NSFontAttributeName, [NSColor redColor], NSForegroundColorAttributeName, nil];
NSAttributedString * newEmail = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d", newUnreadEmail] attributes:attributes];
[newEmail drawAtPoint:NSMakePoint(140, 600)];
You need to do math to calculate the correct point for the right alignment. Use
[newEmail size]to calculate the width of the attributed string, subtract it from the width of the rectangle in which you would like it painted, and add the difference to the left coordinate of the point that you pass to thedrawAtPoint:method.