-1
我用CAShapeLayer
创建了一圈圆圈UIViews
(圈内圆)。 阴影在UIView周围不可见
现在我想为每个圆圈添加阴影。它应该是每个圈子周围的阴影。所以我喜欢这个。
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
}
在我的UIViewController
我这样调用这个方法。
for addedcircle in circleStack
{
self.view.addSubview(addedcircle)
let deco=CircleDeco()
deco.setCircleShadow(circle: addedcircle)
}
但是我的阴影在UIViews
附近不可见。请告诉我最新的错误与我的代码。
UPDATE
Circle类绘制方法调用这一点,并建立社交圈
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)")
}
然后在我的视图控制器我加入这些使用for循环的圆圈
尝试改变偏移 circle.layer.shadowOffset = CGSize.init(宽度:5,高度:5) –
@VinayKumar试图circle.layer .shadowOffset = CGSize.init(宽度:5,高度:5)但没有运气:( – das
提供足够的代码以允许您的结果被再现 – matt