我在Xcode中创建了这个UIImageView,然后添加了一个图像。见下图:
然后我添加了这段代码以尝试更改UIImageView但它无法正常工作:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var border: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let width = UIScreen.mainScreen().bounds.width
let height = UIScreen.mainScreen().bounds.height
border.frame.size.width = width
border.frame.size.height = height
}
答案 0 :(得分:1)
我相信您必须在 ViewDidLayoutSubviews 中执行此操作,而不是ViewDidLoad:
override func viewDidLayoutSubviews() {
}