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. 將容器類的高度設置爲圖像的高度
- 3. UINavigationController設置視圖高度?
- 4. 如何訪問堆棧視圖中的視圖控制器?
- 5. 容器視圖設置高度取決於孩子
- 6. 其他容器內的藍圖容器,設置高度:100%
- 7. 堆棧設置
- 8. 如何在不定義容器高度的情況下設置高圖中字幕的高度?
- 9. 如何設置圖庫視圖單元格的高度等於圖庫高度?
- 10. 在哪裏設置導航堆棧中的視圖控制器導航項目
- 11. 修改容器視圖的高度
- 12. 設置Google地圖容器DIV的寬度和高度100%
- 13. 在高圖中設置符號高度
- 14. Xcode:視圖控制器何時添加到視圖堆棧中?
- 15. 將一排CSS Flexbox容器的高度設置爲特定容器的高度
- 16. 如何將容器DIV的高度設置爲窗口高度的100%?
- 17. 如何設置按鈕的高度視口高度
- 18. CSS/HTML:設置默認容器高度
- 19. 堆棧視圖在表視圖細胞
- 20. 如何在knitr中設置圖的寬度/高度?
- 21. 如何將桌子高度設置爲垂直滾動容器的高度?
- 22. 如何使用CSS將div的高度設置爲其容器高度?
- 23. 堆棧視圖隱藏了視圖,堆積在其中
- 24. 如何在視圖OnMeasure上以最小高度設置wrap_content?
- 25. 在HTML5中設置視頻高度
- 26. 如何將標籤高度設置爲內容高度
- 27. Android:設置視圖高度爲0
- 28. reloadData後設置集合視圖高度
- 29. ForeceFully將視圖高度設置爲零
- 30. 如何將視圖的高度/寬度(f.e. Label)設置爲其在Xamarin.Forms中的內容大小?
非常感謝你。幫助我更瞭解堆棧視圖 – Lachtan