I don't understand how this works. If I draw a UIView object to my UIViewController .xib file, then my UIView redraws itself. If I add it to the subView like
CustomView : UIView
in UIViewController's viewDidLoad
CustomView *v = [[CustomView alloc] initWithFrame:self.view.frame];
[self.view addSubview:v];
The CustomView not draw itself. I then tried to do
[self.view setNeedsDisplay];
and I still get nothing. Just a white background (different than the black background I was getting before), but none of my drawing. How does it work when you add a UIView programmatically? thanks.
You might simply be setting the frame of CustomView incorrectly.
ReplyDeleteEach view has its own coordinate space, with (0, 0) at the upper left corner. A view's frame is in its parent's coordinate space. This mean that it is often wrong to set a view's frame to be the same as its superview's frame.
A view's bounds is in the view's own coordinate space. So if you want to make your CustomView exactly cover its superview, you should set the CustomView's frame to its superview's bounds.
Try this:
CustomView *v = [[CustomView alloc] initWithFrame:self.view.bounds];