-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。 –