作为初学者,我不得不说理解如何创建自定义UI以及Cocoa / UIKit一般如何工作对我来说非常复杂,所以我正在尝试......
所以这里有一些代码:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let myRect = CGRect(x: 10, y: 50, width: self.view.bounds.width-20, height: 300)
let roundedRectangle = UIBezierPath(rect: myRect)
let shapeLayer = CAShapeLayer()
shapeLayer.path = roundedRectangle.CGPath
shapeLayer.fillColor = UIColor.whiteColor().CGColor
shapeLayer.shadowColor = UIColor.blackColor().CGColor
shapeLayer.shadowOpacity = 0.5
shapeLayer.shadowRadius = 2
shapeLayer.shadowOffset = CGSize(width: 0, height: 0)
self.view.layer.addSublayer(shapeLayer)
}
}
我很了解它,它给了我这个结果:
我想了解几件事: