2016-11-19 30 views
1

我目前正在使用包含幾個垂直對齊元素的堆棧視圖。我正在做一切代碼。使用自動佈局減少文本字段周圍的空間

我已經標記了每個堆棧視圖的子視圖。下面是截圖:

enter image description here

這是stackview代碼:

func setUpVerticalLayoutStackView() { 
    stackViewForVerticalLayout = UIStackView(arrangedSubviews: [viewTitleButton, stackViewForTheTwoPersons, owedButton, amountTextField, doneButton]) 
    stackViewForVerticalLayout.axis = .vertical 
    stackViewForVerticalLayout.distribution = .equalCentering 
    stackViewForVerticalLayout.alignment = .center 
    stackViewForVerticalLayout.spacing = 20 
    stackViewForVerticalLayout.translatesAutoresizingMaskIntoConstraints = false 
    self.addSubview(stackViewForVerticalLayout) 
} 

我的問題是:爲什麼文本字段佔據這麼大的空間?我可以以某種方式減少它嗎?

不要介意視圖中心的「r」,它只是我錯誤地添加到圖像編輯器中的東西。

+0

根據您的需要將'stackViewForVerticalLayout.distribution'更改爲'.equalSpacing'或'.fillEqually'。這將減少這個領域的這個大小。 – Wes

+0

謝謝@韋斯,這解決了它。你能否將它寫在答案中,以便我可以將其標記爲正確並解決? –

+0

沒問題,謝謝! – Wes

回答

2

更改stackViewForVerticalLayout.distribution.equalSpacing.fillEqually取決於你想要什麼。這將減小該字段的大小