【问题标题】:Changes in Xcode 9 not reflecting in mainStoryboard, however, same changes are reflecting in simulatorXcode 9 中的更改未反映在 mainStoryboard 中,但是,相同的更改反映在模拟器中
【发布时间】:2018-03-08 22:57:56
【问题描述】:

我正在尝试通过编写代码来设置图像的尺寸,但是当我尝试运行代码时,它可以工作并在模拟器中显示更改,但在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.
   }
}

【问题讨论】:

  • 代码在运行时执行,这就是它没有显示在故事板上的原因。此外,您没有使用故事板图像视图。

标签: swift xcode storyboard ios-simulator


【解决方案1】:

故事板不是您的应用程序中正在运行的内容的实时视图。 Storyboard 只会显示其中的视图。如果您在 ViewController 中以编程方式创建视图(您的 UIImageView),它们将不会出现在您的 Storyboard 中,因为它们从未接触过它。

【讨论】:

    猜你喜欢
    • 2014-12-03
    • 2015-10-26
    • 2021-08-18
    • 1970-01-01
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    相关资源
    最近更新 更多