UIView change background transparency

background, iphone, objective-c, transparency

Solution

There is a simple trick for this. Add a subview of same frame and change it's alpha.

UIView *popupView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
UIView *bgView = [[UIView alloc] initWithFrame:popupView.frame];
UIColor * bgColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_bg.png"]];
bgView.backgroundColor = bgColor;
bgView.alpha = 0.5;
[popupView addSubview:bgView];

Problem

I am working on an Iphone Application. I am creating a UIView: ``` UIView *popupView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)]; ``` Then I want to use an image as a background for the view: ``` UIColor * bgColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_bg.png"]]; popupView.backgroundColor = bgColor; ``` Is there a way I can make that background semi transparent? maybe set the alfa value to 0.5 or give it an opacity. I tried to make the image transparent using photoshop but when I set it as a background it is no longer transparent. Note that I need only the background to be transparent not the subviews Thanks a lot for any help

Original source