3

我正在开发一个 Iphone 应用程序。

我正在创建一个 UIView:

UIView *popupView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];

然后我想使用图像作为视图的背景:

UIColor * bgColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_bg.png"]];

popupView.backgroundColor = bgColor;

有没有办法让背景半透明?可能将 alfa 值设置为 0.5 或给它一个不透明度。

我尝试使用 Photoshop 使图像透明,但是当我将其设置为背景时,它不再透明。

请注意,我只需要背景透明而不是子视图

非常感谢您的帮助

4

2 回答 2

8

有一个简单的技巧。添加同一帧的子视图并将其更改为 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];
于 2012-12-13T10:26:17.377 回答
1

您可以将 alpha 降低到 0.5 以使其透明或根据需要进行更改。

你可以参考这个链接

于 2012-12-13T10:28:17.123 回答