2017-10-06 112 views

回答

0

這與提供的鏈接幾乎是相同的任務,只需更改BezierPath即可。

let block1 = UIView(frame: CGRect.init(x: 50, y: 50, width: 300, height: 300)) 
block1.backgroundColor = UIColor.red 

block1.layer.masksToBounds = false 
block1.layer.shadowOffset = CGSize(width: 0.0, height: 0.0) 
block1.layer.shadowRadius = 5.0 
block1.layer.shadowOpacity = 0.7 

let path = UIBezierPath() 
path.move(to: CGPoint(x: 0.0, y: 0.0)) 
// Move to center between two top points instead of bottom 
path.addLine(to: CGPoint(x: block1.frame.size.width/2.0, y: block1.frame.size.height/2.0)) 
path.addLine(to: CGPoint(x: block1.frame.size.width, y: 0.0)) 
path.addLine(to: CGPoint(x: block1.frame.size.width, y: block1.frame.size.height)) 
path.addLine(to: CGPoint(x: 0.0, y: block1.frame.size.height)) 
path.close() 
block1.layer.shadowPath = path.cgPath 
相關問題