gpt4 book ai didi

iphone - UIView改变背景透明度

转载 作者:搜寻专家 更新时间:2023-10-30 19:55:03 25 4
gpt4 key购买 nike

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

我正在创建一个 UIView:

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

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

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

popupView.backgroundColor = bgColor;

有没有办法让背景变成半透明的?也许将 alfa 值设置为 0.5 或给它一个不透明度。

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

注意我只需要背景透明而不是 subview

非常感谢您的帮助

最佳答案

有一个简单的技巧。添加同一帧的 subview 并更改它的 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];

关于iphone - UIView改变背景透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13857677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com