I'm attempting to create an IBDesignable class which can have a transparent background when rendered in Interface Builder. So far, I've gotten opaque black backgrounds. I've set up a simple demonstration of the issue:
I've placed a UIView in this scene in Interface Builder. You can't see it because its background is clear. This is what should the scene should look like.
The only difference in this screenshot is that I've set the class of our previously invisible view to be 'DesignableView'.
Here is the entire implementation of the DesignableView class:
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface DesignableView : UIView
@end
@implementation DesignableView
- (void)drawRect:(CGRect)rect {
//rendering code goes here
}
@end
Is there a way to give the IBDesignable view the correct, transparent background?
I just remembered how I fix this. You need to override layoutSubviews
- (void)layoutSubviews
{
[super layoutSubviews];
self.backgroundColor = [UIColor clearColor];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With