6
A
回答
7
'填充比例' 分配型與內在含量的大小工作。因此,如果我們的垂直堆棧(高度爲600)視圖具有2個視圖,ViewA(內在內容高度200)和ViewB(內在內容高度100),堆棧視圖將它們的大小設置爲ViewA(高度400)和ViewB(高度400)身高200)。
此外,
- 如果所有的觀點並不具有內在的內容高度,垂直堆棧視圖將始終顯示的IB錯誤「需求約束:Y位置或高度」。
- 沒有固有高度的視圖將摺疊到零高度。
- 具有固有高度的視圖將按比例分配自己。
你真正想要的是什麼
是'填充' 式分佈有兩個約束。
- ViewA.height = 2 * ViewB.height
- ViewB.height = 0.5 * ViewC.height
這就是所有。希望能幫助到你。
0
你也可以實現它編程,你可以消除一個文本字段,然後用堆棧視圖的填充同樣分佈將其返回,類似如下:
class LoginViewController: UIViewController{
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
nameTextField.translatesAutoresizingMaskIntoConstraints = false
emailTextField.translatesAutoresizingMaskIntoConstraints = false
passwordTextField.translatesAutoresizingMaskIntoConstraints = false
}
// IBAction
@IBAction func registerLoginSegmented(_ sender: Any) {
if (sender as AnyObject).selectedSegmentIndex == 0{
// Before we resize (shrink) the nameTextField, change the stackview' distribution from "fill equally" to just "fill"
stackView.distribution = .fill
// Change the nameTextField's text
heightConstraintNameTextField = nameTextField.heightAnchor.constraint(equalToConstant: 0)
heightConstraintNameTextField?.isActive = true
// Rearrange the height of the emailTextField
heightConstraintEmailTextField = emailTextField.heightAnchor.constraint(equalToConstant: 50)
heightConstraintEmailTextField?.isActive = true
// Rearrange the height of the passwordTextField
heightConstraintPasswordTextField = passwordTextField.heightAnchor.constraint(equalToConstant: 50)
heightConstraintPasswordTextField?.isActive = true
}
else {
// Return the nameTextField by simply trun off the constrants and assign "fillEqually" instead of "fill"
heightConstraintNameTextField?.isActive = false
heightConstraintEmailTextField?.isActive = false
heightConstraintPasswordTextField?.isActive = false
stackView.distribution = .fillEqually
}
}
相關問題
- 1. 根據子視圖自動設置容器視圖的高度
- 2. Android:如何設置視圖的高度?
- 3. 如何爲嵌入在另一個堆棧視圖中的堆棧視圖設置頂部佈局約束?
- 4. 將容器類的高度設置爲圖像的高度
- 5. UINavigationController設置視圖高度?
- 6. 如何訪問堆棧視圖中的視圖控制器?
- 7. 視圖設置爲View.GONE仍然在視圖堆棧上?
- 8. 如何設置堆棧段
- 9. 容器視圖設置高度取決於孩子
- 10. 其他容器內的藍圖容器,設置高度:100%
- 11. 視圖控制器堆棧
- 12. 堆棧設置
- 13. 如何在不定義容器高度的情況下設置高圖中字幕的高度?
- 14. 如何設置圖庫視圖單元格的高度等於圖庫高度?
- 15. 如何設置容器div的寬度和高度?
- 16. 在哪裏設置導航堆棧中的視圖控制器導航項目
- 17. 修改容器視圖的高度
- 18. 設置Google地圖容器DIV的寬度和高度100%
- 19. 從容器視圖內的視圖將視圖推入導航堆棧?
- 20. 如何在瀑布視圖中自動設置圖像寬度和高度?
- 21. 在高圖中設置符號高度
- 22. Xcode:視圖控制器何時添加到視圖堆棧中?
- 23. 將一排CSS Flexbox容器的高度設置爲特定容器的高度
- 24. 如何將容器DIV的高度設置爲窗口高度的100%?
- 25. 如何在html上設置餘輝播放器中的視頻高度/寬度
- 26. 如何設置按鈕的高度視口高度
- 27. CSS/HTML:設置默認容器高度
- 28. jQuery設置容器和頁腳高度
- 29. 在android中設置圖像視圖的高度
- 30. 將圖像高度設置爲容器高度並保持寬高比
非常感謝你。幫助我更瞭解堆棧視圖 – Lachtan