Correct way to draw background using a pattern image


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.