【问题标题】:Making transparent Circles in iOs在 iOs 中制作透明圆圈
【发布时间】:2015-03-10 01:54:45
【问题描述】:

我想创建一个带有透明圆圈的黑色 UIView。

我考虑创建一个视图(黑色和透明度 50%),并在其中添加多个圆圈,但我不知道如何为每个设置透明度。我知道如何创建一个圆形视图(例如:how to draw a custom uiview that is just a circle iphone-app)。

我想做的是类似于iShowcase library 但有多个点:

有什么线索吗?谢谢。

已解决

我查看了iShowcase library 的代码并解决了我的问题。现在,我在位于iShowcase library 的图书馆工作。 完成后我会在这里发布。

【问题讨论】:

    标签: ios ios7 uiview ios8


    【解决方案1】:

    请查看以下链接,希望这对您有所帮助。 链接: Here is Answer to set shadow in your view.

    【讨论】:

      【解决方案2】:

      为您的 circleView 使用 alpha。与您的链接示例一样,然后在您的主视图中添加为子视图:

          UIView *circleView = [[UIView alloc] initWithFrame:CGRectMake(10,20,100,100)];
          circleView.alpha = 0.5;
          circleView.layer.cornerRadius = 50;
          circleView.backgroundColor = [UIColor whiteColor];
          [yourmainview addSubview: circleView];
      

      顺便说一句,在您的图片中,我认为白色圆圈具有 100% 的 alpha。您可以为每个 circleView 使用单独的 alpha,或者使用随机器 :)

      至于更新的示例,为什么不在 h 文件中添加更多按钮和展示,合成它们并使用多个实例....展示 setupShowcaseForTarget:btn_custom_1 title:@"title" details:@"other"]; ?我认为你应该修改主类,因为你想要的是不同的 containerView 用于多个视图 [circles]。

      使用修改后的 iShowcase.m [- (void) calculateRegion] 和不同的视图作为容器,我可以制作类似:http://tinypic.com/view.php?pic=2iwao6&s=8#.VLPTRqYsRE8 所以答案是:使用自定义视图进行多个展示 [ex [showcase2 setContainerView: self.view2];],然后为每个展示柜自定义框架 [showcase2.frame = CGRectMake(0,0,100,100);] 我没有时间对示例进行微调,但是是的,您可以获得所需的结果...

      【讨论】:

      • 我认为我没有正确解释我自己,我会更新我的问题。
      • 我更新它看起来 github.com/rahuliyer95/iShowcase 我想要类似的东西,但有多个圆圈和文字。
      【解决方案3】:

      我终于解决了受 iShowCase 库启发的问题,我做了这个简单的类并上传到 github。

      https://github.com/tato469/FVEasyShowCase

      【讨论】:

        【解决方案4】:

        您可以做的最简单的事情是让您的主视图(黑色 50% 透明)并向其蒙版层添加形状。

        所以基本上:

        //Set up your main view.
        UIView* mainView = [UIView new];
        mainView.backgroundColor = [UIColor blackColor];
        mainView.alpha = 0.5;
        
        UIView* circle1 = [YourCircleClassHere new];
        UIView* circle2 = [YourCircleClassHere new];
        UIView* circle3 = [YourCircleClassHere new];
        
        UIView* container = [UIView new];
        
        [UIView addSubview:circle1];
        [UIView addSubview:circle2];
        [UIView addSubview:circle3];
        
        //Make a new layer to put images in to mask out
        CALayer* maskLayer = [CALAyer layer];
        //Assign the mask view to the contents layer.
        maskLayer.contents = (id)container;
        //This will set the mask layer to the top left corner.
        maskLayer.frame = CGRectMake(0,0,container.frame.size.width,container.frame.size.height);
        //Lastly you assign the layer to the mask layer of the main view.
        mainView.layer.mask = maskLayer;
        //Applies basically the same as clipToBounds, but a bit reversed..
        mainView.layer.mask = true/false;
        

        附注:

        我使用图像“contents = (id) [UIImage CGImage]”实现了这一点,但我确信它也应该适用于 UIViews。

        还要注意一些错误,因为我只是从脑海中写出来的,所以我也没有测试过..所以如果它有效,请随时更新/!有效^_^

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-10-09
          • 2022-01-26
          • 1970-01-01
          • 2013-03-13
          • 2013-11-25
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多