-1

Is there a way to repeat an UIImage inside a rectangle using CoreGraphics? It's kind of like http://www.raywenderlich.com/33496/core-graphics-tutorial-patterns, but I'm gonna use an image loaded from file.

Jonny
  • 15,384
  • 14
  • 105
  • 222

1 Answers1

3

Use the image as a pattern color:

UIColor *color = [[UIColor alloc] initWithPatternImage:myImage];
someView.backgroundColor = color;

Not exactly Core Graphics, though. If you really need it there's CGColorCreateWithPattern. It's a bit more code to set up.

Nikolai Ruhe
  • 80,564
  • 16
  • 176
  • 197
  • That's cool. I'm trying to make a SKTexture and/or SKSpriteNode out of it in the end and seeing as there is `[SKSpriteNode spriteNodeWithColor:colorTest size:CGSizeMake(300, 300)];` I gave it a go, alas it doesn't seem to like a "image color". – Jonny Sep 18 '13 at 10:35
  • 1
    @Jonny See http://stackoverflow.com/questions/19490970/sprite-kit-and-colorwithpatternimage/19833309#19833309 – David Lawson Nov 07 '13 at 10:19