-4
我試圖通過編寫代碼來設置圖像的尺寸,但是當我嘗試運行代碼時它的工作原理和顯示模擬器,但不是在MainStoryboard
。爲什麼會發生這種情況?Xcode 9中的變化沒有反映在mainStoryboard中,但是,在模擬器中反映的變化相同
Import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let imageView = UIImageView(frame: CGRect(x: 100, y: 500, width: 258, height: 64)); // set as you want
let image = UIImage(named: "signInLogo.png");
imageView.image = image;
self.view.addSubview(imageView);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
該代碼在運行時執行,這就是爲什麼它不顯示在故事板上。 此外,你沒有使用你的故事板imageview。 –