2

I've created a simple view that will show some AVPlayer content, or if this does not exist (initial state) draw a splash image.

I've added the IB_DESIGNABLE directive, and am drawing the splash image in drawRect. However, in Interface Builder, the component renders as a black square. I'd like it to draw the image. Is this possible?

At runtime all works fine.

Jasper Blues
  • 28,258
  • 22
  • 102
  • 185

2 Answers2

2

To investigate what goes on within the IB rendition for your drawRect: implementation, I would recommend to debug how your view behaves with IB using the debugger.
For that, select your view in IB, and then use the Debug Selected Views item from the Editor menu in XCode. By setting up a breakpoint in the drawRect: you should be able to understand what's going on and why you get a black square.

yonel
  • 7,855
  • 2
  • 44
  • 51
  • I'd solved this but forgot I had asked on SO. Turned out the image was nil during IB's pass at drawRect. Setting the image via IB helped. Useful info all the same – Jasper Blues Feb 09 '15 at 01:09
1

Just for reference, you can set custom variables in IB (such as your images) using the keyword IBInspectable, f.e. as:

IB_DESIGNABLE
@interface MyCustomControl : UIView
{
    IBInspectable UIImage *myImage;
    ...
}
...
@end

For more info read this awesome blog where I found that keyword (I had been looking for something like that for quite a while).

Daniel
  • 20,420
  • 10
  • 92
  • 149