Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 快速阴影无法正确扩散_Swift_Shadow_Sketchapp - Fatal编程技术网

Swift 快速阴影无法正确扩散

Swift 快速阴影无法正确扩散,swift,shadow,sketchapp,Swift,Shadow,Sketchapp,我一直在尝试为我的UIView创建一个阴影。我环顾四周,从这篇文章中找到了CALayer类的扩展 到目前为止,它一直在为我工作,直到我试图把一个非0的数字,为传播 价差为0。这就是结果 这是使用1的排列得到的结果 如果传播速度达到5,情况会变得更糟 我遇到的问题是它没有圆角,我不知道如何解决这个问题。下面是我使用此视图的UIView的代码。用于生成阴影的扩展位于上面的帖子中 UIView代码 class FileCalculateOperatorSelectionButton : UIVi

我一直在尝试为我的UIView创建一个阴影。我环顾四周,从这篇文章中找到了CALayer类的扩展

到目前为止,它一直在为我工作,直到我试图把一个非0的数字,为传播

价差为0。这就是结果

这是使用1的排列得到的结果

如果传播速度达到5,情况会变得更糟

我遇到的问题是它没有圆角,我不知道如何解决这个问题。下面是我使用此视图的UIView的代码。用于生成阴影的扩展位于上面的帖子中

UIView代码

class FileCalculateOperatorSelectionButton : UIView {

    private var isActivated : Bool = false

    //Background colors
    private var unSelectedBackgroundColor : UIColor = UIColor(red: 178/255, green: 90/255, blue: 253/255, alpha: 1.0)
    private var selectedBackgroundColor : UIColor = UIColor.white
   
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.commonInit()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        self.commonInit()
    }

    private func commonInit() {
        self.layer.cornerRadius = self.frame.height/2
        self.backgroundColor = self.unSelectedBackgroundColor
    
        let shadowColor = UIColor(red: 0xC8, green: 0xC6, blue: 0xC6)

        //Change the spread argument here
        self.layer.applySketchShadow(color: .black, alpha: 0.5, x: 0, y: 0, blur: 5, spread: 0)
    }   
}

尝试将
层的
masksToBounds
属性设置为
true

self.layer.masksToBounds = true

更改
CALayer
扩展中
applySketchShadow
中的
shadowPath
函数,如下所示

// shadowPath = UIBezierPath(rect: rect).cgPath
shadowPath = UIBezierPath(roundedRect: rect, cornerRadius: cornerRadius).cgPath 
价差:1

检查这个。。