Advertisement
trss

NSAttributedString's boundingRectWithSize:options:

Sep 21st, 2012
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)drawRect:(NSRect)dirtyRect
  2. {
  3.     NSFont *font = [NSFont fontWithName:@"Zapfino" size:40.0];
  4.     NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"flapfino\ntest" attributes:[NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]];
  5.  
  6.     NSRect viewBounds = [self bounds];
  7.     NSRect stringBounds = [string boundingRectWithSize:viewBounds.size options:NSStringDrawingUsesLineFragmentOrigin];
  8.     stringBounds.origin.x = NSWidth(viewBounds) / 2 - NSWidth(stringBounds) / 2;
  9.     stringBounds.origin.y = NSHeight(viewBounds) / 2 - NSHeight(stringBounds) / 2;
  10.    
  11.     [[NSBezierPath bezierPathWithRect:stringBounds] stroke];
  12.    
  13.     [string drawInRect:stringBounds];
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement