Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save demigod19892012/5311149 to your computer and use it in GitHub Desktop.
Save demigod19892012/5311149 to your computer and use it in GitHub Desktop.
[IOS] Correct way to draw background using a pattern image
[[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