Posted By

cphoover on 08/03/12


cocoa Development

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


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];
  4. // Change the pattern phase.
  5. [[NSGraphicsContext currentContext] setPatternPhase:
  6. NSMakePoint(0,[self frame].size.height)];
  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]);
  13. // Restore the original graphics state.
  14. [[NSGraphicsContext currentContext] restoreGraphicsState];

Report this snippet  


RSS Icon Subscribe to comments
Posted By: Jacky888 on September 27, 2018

the 8 best rock out portable speaker review topportablespeaker

You need to login to post a comment.