Skip to content

Instantly share code, notes, and snippets.

@MilkZoft
Created January 18, 2012 22:01
Show Gist options
  • Select an option

  • Save MilkZoft/1636075 to your computer and use it in GitHub Desktop.

Select an option

Save MilkZoft/1636075 to your computer and use it in GitHub Desktop.
codejobs - Correct way to draw background using a pattern image - Objective-C
// Save the current graphics state first so we can restore it.
[[NSGraphicsContext currentContext] saveGraphicsState];
// Change the pattern phase.
[[NSGraphicsContext currentContext] setPatternPhase:
NSMakePoint(0,[self frame].size.height)];
// Stick the image in a color and fill the view with that color.
NSImage *anImage = [NSImage imageNamed:@"bricks"];
[[NSColor colorWithPatternImage:anImage] set];
NSRectFill([self bounds]);
// Restore the original graphics state.
[[NSGraphicsContext currentContext] restoreGraphicsState];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment