How can I use CGContextDrawTiledImage to tile an image?

前端 未结 5 1084
死守一世寂寞
死守一世寂寞 2020-12-05 03:36

I want to be able to an UI object like a UIImageView and tile an image inside of it.

I have been able to use CGContextDrawTiledImage to update the background in the

5条回答
  •  甜味超标
    2020-12-05 04:24

    Sorry for not knowing how to add comment to other's answers, so I created a new answer here:

    I just want to point out the answer provided by Kailoa Kadano has a bug, the image_rect.origin is not initialized properly.

    About 3 weeks ago, I copied his code in my project, and it seems working. However, yesterday, I tried to run the code in ios simulator(iphone 4.3), it just hang in CGContextDrawTiledImage. After adding the following line as showed in keremk's answer:

    image_rect.origin = CGPointMake(0.0, 0.0);
    

    it works again!

    It's rather tricky, actually at first I tested under iphone 4.3 simulator, then recently I tested under iphone 4.0 simulator, then yesterday when I switched back to 4.3 simulator or 4.2 simulator, the problem occurs. That is the image_rect.origin is undefined, sometimes it's zero data, maybe sometimes it has some random data.

提交回复
热议问题