我做了一個繼承自UIView的類。在那個課上,我想畫一個PNG圖像。但是,當我在viewcontroller中運行它時,它似乎沒有做任何事情。我讀過,我們必須使用setNeedsDisplay才能夠在viewcontroller中調用drawRect。它似乎沒有更新。從視圖控制器繪製類swift
class MyView: UIViewController{
let tile = DrawTile()
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Pressed(sender: AnyObject) {
tile.setNeedsDisplay()
}
}
class Draw: UIView {
override func drawRect(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
let image = UIImage(named: "test.png")
let location = CGPointMake(0, 0)
image?.drawAtPoint(location)
}
}
瓷磚是平局或DrawTile? – Chiko
你可以在啓動應用程序時看到圖像嗎? – Chiko
我在啓動應用程序時看不到圖像。 – user187558