0
明顯監督一些簡單的事情。需要訪問嵌套堆棧視圖另一個堆棧視圖。訪問嵌套堆棧視圖
如果我想爲乘客2設置所有嵌套的堆棧視圖的間距,我該怎麼做?
// Select passenger 2
let tag = 2
// Select wrapper stackView for passenger 2
let stackView = self.view.viewWithTag(tag) as! UIStackView!
let nestedStackViews = stackView. <-- WHAT GOES HERE??
for sv in nestedStackViews{
sv?.spacing = 0 // Set nested stackView spacing to 0 to avoid constraint issues
}
可視化(需要firstName_P2,surname_P2和email_P2的間距設置爲0)
SOLUTION:根據冬季的回答
提供其他更詳細的誰可能會掙扎,請務必將子視圖轉換爲堆棧視圖
// Select passenger 2
let tag = 2
// Select wrapper stackView for passenger 2
let stackView = self.view.viewWithTag(tag) as! UIStackView!
if let nestedStackViews = stackView?.subviews{
for sv in nestedStackViews{
let nsv = sv as! UIStackView
nsv.spacing = 0
}
}
謝謝!之前已經嘗試過 - 但是從你身上看到它使我意識到將子視圖轉換爲堆棧視圖。 –