【发布时间】: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