参见英文答案 >
Calling instance method during initialization in Swift7个
我上课了
我上课了
class ChartView: UIView { class: DotView { let circleView1: UIView let circleView2: UIView init (view: UIView) { self.view = view self.circleView1 = self.buildCircle(some rect here) self.circleView2 = self.buildCircle(some rect here) func buildCircle(rect: CGRect) -> UIView { let dotView = UIView(frame: rect) dotView.backgroundColor = UIColor.whiteColor() dotView.layer.cornerRadius = dotView.bounds.width / 2 self.view.addSubview(dotView) return dotView } } }