Posted By

andyr on 03/05/11


Tagged

cocoa Development


Versions (?)

Correct way to draw background using a pattern image


 / Published in: Objective C
 

  1. // Save the current graphics state first so we can restore it.
  2. [[NSGraphicsContext currentContext] saveGraphicsState];
  3.  
  4. // Change the pattern phase.
  5. [[NSGraphicsContext currentContext] setPatternPhase:
  6. NSMakePoint(0,[self frame].size.height)];
  7.  
  8. // Stick the image in a color and fill the view with that color.
  9. NSImage *anImage = [NSImage imageNamed:@"bricks"];
  10. [[NSColor colorWithPatternImage:anImage] set];
  11. NSRectFill([self bounds]);
  12.  
  13. // Restore the original graphics state.
  14. [[NSGraphicsContext currentContext] restoreGraphicsState];

Report this snippet  

You need to login to post a comment.