You*_*sef 3 iphone transparency background objective-c
我正在研究Iphone应用程序.
我正在创建一个UIView:
UIView *popupView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
Run Code Online (Sandbox Code Playgroud)
然后我想使用图像作为视图的背景:
UIColor * bgColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_bg.png"]];
popupView.backgroundColor = bgColor;
Run Code Online (Sandbox Code Playgroud)
有没有办法让背景半透明?也许将alfa值设置为0.5或赋予其不透明度.
我尝试使用photoshop使图像透明,但当我将其设置为背景时,它不再是透明的.
请注意,我只需要背景是透明的而不是子视图
非常感谢您的帮助
有一个简单的技巧.添加相同帧的子视图并更改其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];
Run Code Online (Sandbox Code Playgroud)