Xcode 9中的变化没有反映在mainStoryboard中,但是,在模拟器中反映的变化相同
问题描述:
我试图通过编写代码来设置图像的尺寸,但是当我尝试运行代码时它的工作原理和显示模拟器,但不是在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.
}
}
答
故事板是不什么是您的应用程序运行的实时视图。故事板只会显示其中的视图。如果您在ViewController
内以语法方式创建视图(您的UIImageView
),则它们不会显示在故事板中,因为它们从不触摸它。
该代码在运行时执行,这就是为什么它不显示在故事板上。 此外,你没有使用你的故事板imageview。 –