IPhone needs to get a CGContextRef reference for additional view
I'm using IBoutlet to get a reference to a Sub-View that I added to the main view in the interface builder, but since that won't give me access to drawRect: I can't get the context to draw. Is there anyway I can still get the graphics context so I can draw the sub-view? How can i do this?
You cannot paint like that; you should make the answer in response to the challenge drawRect
, but not at any time, as some frameworks allow.
The correct way to do it is to subclass UIView in Xcode. Switch to Interface Builder, select the subtitle and change its "Identity Class" (under "Tools> Identity Inspector") to the name of your new subclass.
Then in your subclass, you can implement drawRect
.
a source to share
Technically, there is a means for one object to become a drawing delegate to another via the view.layer.delegate route. You can build a delegate to implement
- (void) drawLayer: (CALayer *) layer inContext: (CGContextRef) ctx
This gives you the ability to reuse drawing instructions as needed. But it can be tedious to read and understand another programmer. Most of them would have avoided this, unless it eliminated code duplication.
a source to share