gpt4 book ai didi

ios - 使 UIView 的一部分可见

转载 作者:行者123 更新时间:2023-12-01 18:07:42 24 4
gpt4 key购买 nike

我想在我的 View 上添加一个“阴影”图像,但是,我希望我的 View 的一部分仍然是“可见的”。当你看截图时,你会更好地理解我想要做什么:enter image description here

我可以添加 UIView在我的 super View 之上,但我怎样才能使特定点“可见”?这实际上意味着使 View 的特定区域具有不同的颜色或不透明。

最佳答案

对于您的问题,我有办法,请尝试以下示例。

1. 第一个 Storyboard设计:我有一个 UIButton

enter image description here

2. 添加黑色 View 作为 subview

    UIView *blackView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
blackView.backgroundColor=[UIColor blackColor];
blackView.alpha=0.6f;
[self.view addSubview:blackView];

现在结果将是:

enter image description here

3. 再增加一个UIImageView,其frame等于button frame
  UIImageView *imageView=[[UIImageView alloc]init];
imageView.frame=self.button.frame; //getting current UIButton bounds
imageView.image=[UIImage imageNamed:@"add_img.png"];
[self.view addSubview:imageView];

现在它看起来和你想要的一样:

enter image description here

关于ios - 使 UIView 的一部分可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37876431/

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