我創建了一個新的子視圖類來繪圖 我已經覆蓋函數drawRect(),但我不能改變 子視圖的背景顏色我用背景方法,但它沒有工作!如何在swift中更改子視圖的背景顏色?
import UIKit
class AbedView:UIView {
override func drawRect(rect: CGRect) {
let color = UIColor.blueColor()
// Do any additional setup after loading the view, typically from a nib.
let cgrRect = CGRect(x: 0, y: 0, width: 100, height: 100)
let newView = UIBezierPath(rect: cgrRect)
print(newView.bounds)
color.set()
newView.lineWidth = 5
newView.stroke()
self.backgroundColor = UIColor.blackColor()
}
}
我試過,但沒有奏效 – abedAssa