我试图了解addArrangedSubview是如何工作的,所以我尝试了一个虚拟项目。这是我的VC:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var stackOutlet: UIStackView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let newView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
newView.backgroundColor = UIColor.darkGray
let newView2 = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
newView2.backgroundColor = UIColor.blue
stackOutlet.addArrangedSubview(newView)
stackOutlet.addArrangedSubview(newView2)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)
启动应用程序时,没有任何显示。我想我必须在stackView中设置一些约束吗?
好吧,为了大家的缘故:您需要使用此=
mapView.heightAnchor.constraint(equalToConstant: 200).isActive = true
mapView.widthAnchor.constraint(equalToConstant: 200).isActive = true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1713 次 |
| 最近记录: |