I'm setting the background color of my UIView (which is within a UIViewController) as follows:
myView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myTransparentBG.png"]];
I've even tried messing with [myView setOpaque:NO];
but the image doesn't appear transparent. It has a black background to it. Am I abel to fix this programmatically? Otherwise, how are we supposed to set a transparent background to our view?
This seems like a question that should have been asked before, but I couldn't find an answer.
Images with a transparent background (i.e., a transparent . png) can be uploaded to be used as a logo or a sticker on your video.
The GIF and PNG formats also both support transparency. If you need any level of transparency in your image, you must use either a GIF or a PNG. GIF images (and also PNG) support 1-color transparency. This basically means that you can save your image with a transparent background.
When using a transparent pattern, after setting the backgroundColor property, you need to set opaque
property to NO
on both view and its layer. Here's a sample:
UIView* paperView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,700)];
paperView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"paper.png"]];
[paperView.layer setOpaque:NO];
paperView.opaque = NO;
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