我想在swift語言中爲我的ViewController設置擱淺的圖像。如何在swift中設置背景圖片?
我使用下面的代碼:
self.view.backgroundColor = UIColor(patternImage: UIImage(named:」bg.png")!)
但應用越來越crash.It是顯示錯誤被拋出,因爲像「bg.png」像
「fatal error: unexpectedly found nil while unwrapping an Optional value」(Because of the 「!」)
刪除「!」符號或檢查nil值以設置backgroundImage –
,因爲Image無法找到,它的nil和您的嘗試強制打開nil值。 – iMuzahid