在背景中更改阴影的颜色

时间:2016-07-25 09:16:42

标签: ios swift background-color shadow

我有一个类似iOS 10 Maps-App的应用程序,或者可能是带控制中心的主屏幕。例如,看看图片。如果您打开控制中心,背景的阴影将变为黑色&透明。如何在我的应用程序中访问此图层或子视图并将此阴影中的颜色更改为另一个阴影。也许是红色还是白色?

enter image description here

编辑:

也许直接使用Framework。 https://github.com/iosphere/ISHPullUp

2 个答案:

答案 0 :(得分:0)

您可以像这样使用 UIVisualEffectView : 的的OBJ-C:

UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];//SELECT STYLE OF YOUR CHOICE
    UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    blurEffectView.frame = self.view.bounds;//view Will be YOUR_VIEW
    blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    [self.view addSubview:blurEffectView];//This add Blur view to your view

<强>夫特:

 let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
    let blurEffectView = UIVisualEffectView(effect: blurEffect)
    blurEffectView.frame = self.view.bounds
    blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    self.view.addSubview(blurEffectView)

答案 1 :(得分:0)

有时睁开眼睛,你会发现你想要的东西。如果您使用相同的Framework,则可以更改一个变量。在框架的示例中,您可以访问&#34; BottomVC&#34;并将以下行添加到viewDidLoad()

weak var pullUpController: ISHPullUpViewController!

    override func viewDidLoad() {
       super.viewDidLoad()
       let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture))
       topView.addGestureRecognizer(tapGesture)
       handleView.arrowSize = CGSize(width: 1 , height: 2)

      //This line change the default 40% black to a 70% white.
      pullUpController.dimmingColor = UIColor.white().withAlphaComponent(0.7)

}

&#34;影子&#34;只是一个普通的视图。 Here你可以看到作者是如何实现这一点的。