문제 설명
특정 UITableViewCells에 고유한 삽입을 추가하는 방법은 무엇입니까? (How to add unique insets to specific UITableViewCells?)
insetsContentViewsToSafeArea
속성이 false
로 설정된 UITableView
가 있습니다. 이렇게 하면 tableView
가 너비에 걸쳐 있습니다. 화면의.
셀의 양과 다른 유형은 서버에 의해 구동되므로 tableView
의 내용을 알 수 있는 방법이 없습니다.
하고 싶은 것:
특정 셀에만 고유한 삽입을 할당합니다.
스크린샷을 게시할 수 없으므로 간단한 낙서를 만들려고 합니다.
이 세 개의 셀은 모두 동일한 UITableView
에 있습니다.
|[가장자리로 이동하는 하나의 셀입니다. ]|
|[여기에 또 하나가 있습니다]|
|‑‑‑‑‑이 셀에는 자체 삽입이 필요합니다‑‑‑‑‑|
질문:
이를 달성하는 가장 좋은 방법은 무엇입니까?
내가 시도한 것:
- 재정의
layoutMarginsDidChange
layoutMargins
를에 직접 추가하려고 합니다. >cellForRowAtIndexPath...
layoutMarginsDidChange
</li> cellForRowAtIndexPath...
layoutMargins
를 직접 추가하려고 합니다.com/questions/47760732/how‑can‑i‑achieve‑have‑an‑uitableview‑set‑the‑insets‑of‑its‑cells‑without‑sett">재정의</a> layoutMarginsDidChange
</li> cellForRowAtIndexPath...
layoutMargins
를 직접 추가하려고 합니다. 참조 솔루션
방법 1:
Create a UITableViewCell subclass for the cell with custom insets.
Then you have 2 options ‑‑
- Add a subview to cell's contentView with constraints ‑‑ these will correspond to your desired insets. This view will act as your " pseudo contentView" (add cell content to it)
- Play around with contentView's insets. (not sure if it'll work)
</ol>
I hope this will get you started.
You can use the cell subclass for all cell cases too if you want ‑‑ with an enum style which you can set in cell for row.
enum Style {
case edgeToEdge
case withInset(inset: UIEdgeInset)
}
inside cell subclass
var insetStyle: Style = .edgeToEdge {
didSet {
//update the constraints of the pseudo content view
}
}
(by ArielSD、Harman Orsay)