Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
572
678
First of all, I think I might be going about this the wrong way so bare with me.

I have a UIView where I draw a bunch of stuff using UIBezierPaths in the drawRect:. I need this drawing as a UIImage.

First problem: Before the drawRect: has actually done its job I don't know the size required for the UIView. So I init the view with an arbitrary size with the intention to crop it after. At the end of the drawRect: I know the bounds of the drawing though.

Second, this is what seems most horrible to me, I need to alloc&init my view, add it as a subview of a visible view. Exit the runloop and then I can take a screenshot by view.layer renderInContext:


So I'm thinking the drawRect: of a UIView is not the right place for me to be drawing stuff if I want a UIImage after. But if it isn't, what is? What's the better approach here?
 
Cheers but that's pretty much the same method I'm doing already.

I think what I will do is create a couple of UIView subclasses where I do less in each drawRect:
Then I can create the views I need from the various bezier paths and just add them to (at this point a known size) a regular UIView and I can create an image out of that one.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.