0
所以我有一個非常簡單的佈局,我已經創建了一個觀點,基本上我希望它看起來像我跟添加約束如下完成後,自動佈局約束不正確?
不過,我最終是另一回事,我不知道爲什麼會發生這種行爲。
所以正好與我在試圖達到我想要的佈局做了簡要總結。
- 中心的X位置「/」標籤
- 設置的indexLabel,可以實現這一說,左側可以看到「1」
- 約束的「代表」標籤「/」標籤
- 最後將「代表字段」限制在的右邊indexLabel和左「銷售代表」 的標籤
private func setupDividerLabelLayout() {
addSubview(dividerLabel)
dividerLabel.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
dividerLabel.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
}
private func setupIndexLabelBackgroundLayout() {
addSubview(indexLabelBackground)
indexLabelBackground.leftAnchor.constraint(equalTo: leftAnchor, constant: 24).isActive = true
indexLabelBackground.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
indexLabelBackground.heightAnchor.constraint(equalToConstant: 24).isActive = true
indexLabelBackground.widthAnchor.constraint(equalToConstant: 24).isActive = true
}
private func setupRepsLabelLayout() {
addSubview(repsLabel)
repsLabel.rightAnchor.constraint(equalTo: dividerLabel.leftAnchor, constant: -16).isActive = true
repsLabel.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
}
private func setupRepsFieldLayout() {
addSubview(repsField)
repsField.rightAnchor.constraint(equalTo: repsLabel.leftAnchor, constant: -8).isActive = true
repsField.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
repsField.leftAnchor.constraint(equalTo: indexLabelBackground.rightAnchor, constant: 8).isActive = true
}
,不從問題中移除的最後幾行。 (如:[1]:https://i.stack.imgur.com/......jpg) – wajeeh
只是注意到編輯 –
使用堆棧視圖,而不是搞亂自動佈局約束手動 –