Ios 在swift中,UIView周围不可见阴影
我已经使用Ios 在swift中,UIView周围不可见阴影,ios,swift,uiview,Ios,Swift,Uiview,我已经使用CAShapeLayer创建了一组圆形ui视图(圆形中的圆形) 现在我想为每个圆添加阴影。它应该是每个圆周围的阴影。所以我喜欢这个 func setCircleShadow(circle:Circle) { circle.layer.shadowColor=UIColor.init(colorLiteralRed: 0.0/255, green: 0.0/255, blue: 0.0/255, alpha: 0.14).cgColor circle.layer.shad
CAShapeLayer
创建了一组圆形ui视图(圆形中的圆形)
现在我想为每个圆添加阴影。它应该是每个圆周围的阴影。所以我喜欢这个
func setCircleShadow(circle:Circle)
{
circle.layer.shadowColor=UIColor.init(colorLiteralRed: 0.0/255, green: 0.0/255, blue: 0.0/255, alpha: 0.14).cgColor
circle.layer.shadowOffset = CGSize.init(width: circle.frame.size.width, height: circle.frame.size.height)
circle.layer.shadowOpacity = 1.0
circle.layer.shadowRadius = 6.0
circle.layer.masksToBounds = false
}
在myUIViewController
中,我以这种方式调用此方法
for addedcircle in circleStack
{
self.view.addSubview(addedcircle)
let deco=CircleDeco()
deco.setCircleShadow(circle: addedcircle)
}
但是我的阴影在ui视图
周围不可见。请告诉我我的代码有什么错误
更新
Circle类draw方法调用此函数并创建圆
func drawCircle()
{
let circlePath = UIBezierPath(arcCenter: CGPoint.init(x: RDcircleEnum.circleCenterX.getValues(), y: RDcircleEnum.circleCenterY.getValues()), radius: CGFloat(self.innerCircleRadius), startAngle: CGFloat(0), endAngle:CGFloat(Double.pi * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.cgPath
//change the fill color
shapeLayer.fillColor = UIColor.blue.cgColor
//you can change the stroke color
shapeLayer.strokeColor = UIColor.red.cgColor
//you can change the line width
shapeLayer.lineWidth = 3.0
shapeLayer.path = circlePath.cgPath
self.layer.mask = shapeLayer
}
这就是如何调用上述方法
open func setupCirclestack(parentFrame:CGRect)->[Circle]
{
var arrayCircles = Array<Any>()
let arrayColor=[UIColor.green,UIColor.blue,UIColor.red,UIColor.purple,UIColor.orange]
var currentCircleRadius = CGFloat((UIScreen.main.bounds.size.width-60)/2)
for i in 0..<CircleValues.sharedInstance.numberOfCircles-1
{
let circle=self.getInnerCircle(currentFrame: parentFrame) as! Circle
circle.backgroundColor=UIColor.white//arrayColor[i]
circle.clipsToBounds=false
arrayCircles.append(circle)
circle.innerCircleRadius = currentCircleRadius
currentCircleRadius = currentCircleRadius - 20
print("New Radius------\(circle.innerCircleRadius)")
}
openfunc setupCirclestack(parentFrame:CGRect)->[Circle]
{
var arrayCircles=Array()
让arrayColor=[UIColor.green,UIColor.blue,UIColor.red,UIColor.purple,UIColor.orange]
var currentCircleRadius=CGFloat((UIScreen.main.bounds.size.width-60)/2)
对于0中的i..请检查您的视图中是否有“clipToBounds”。可能是真的。请在每个视图中将其切换为false
view.clipToBounds = false
此参数将剪切所有多余的视图边界尝试将偏移更改为circle.layer.shadowOffset=CGSize.init(宽度:5,高度:5)@VinayKumar尝试过circle.layer.shadowOffset=CGSize.init(宽度:5,高度:5),但运气不佳:(提供足够的代码以允许复制结果。另一个猜测是颜色alpha值太小。请添加更多有助于解决问题的代码。@matt请检查更新的部分。