[英]Reduce Form spacing between sections SwiftUI
我正在嘗試使用 SwiftUI 制作一個筆記應用程序,我想展示類似於Apollo Reddit 應用程序的筆記。
它顯示帖子的方式並沒有什么特別之處,它只是使用類似於帶有GroupedListStyle()
的列表的界面來顯示帖子,但各部分之間的間距較小。
我已經嘗試了很多技巧來減少這個間距,但它們似乎都不起作用。
任何幫助表示贊賞。 提前致謝!
這是我的代碼:
import SwiftUI
struct NotesView: View {
let array = [
Note(title: "Mi pana miguel letra", content:
"""
[Intro: Keyan JRN & Producer Tag]
El pana Miguel, yah, ey
El pana Miguel, yah, ey (Snorkatje)
Mi pana, mi pana, yeah
Mi pana, mi pana, yeah
Mi pana, mi pana, yeah, eh-eh
Uh-uh-uh-uh-uh-uh
[Estribillo]
Ha-ha-hace un rato conocí al pana Miguel
No-no voy a mentir, se ve bastante fresco
(Ey, tío, ¿conoces a IlloJuan?) ¿Quién?
(IlloJuan) No, que quién te ha preguntado (No-oh)
Ha-hace un rato conocí al pana Miguel (Pana Miguel)
No voy a mentir, se ve bastante fresco (Bastante fresco)
Y el desgraciado de Matías que se vaya ya (Uh-uh, uh, uh)
Prefiero quedarme aquí con mi pana, sentado
"""
),
Note(title: "Note 02", content: "This is a test note."),
Note(title: "Note 03", content: "This is a test note that is supposed to be longer than just 3 lines to test the note preview. Since I cba to write...")
]
@ObservedObject var searchBar: SearchBar = SearchBar()
var body: some View {
NavigationView {
List {
if array.count > 0 {
ForEach(
array.filter
{
searchBar.text.isEmpty ||
$0.id.localizedStandardContains(searchBar.text)
},
id: \.self
) { eachNote in
Section {
NoteView(note: eachNote)
}.buttonStyle(PlainButtonStyle())
}
} else {
NavigationLink(destination: NotesTextEditor()) {
Text("Create a new post")
}
}
}
.listStyle(GroupedListStyle())
.add(self.searchBar)
}
}
}
可能的解決方案是使用自定義 a-la 組分隔符,而不是標准。
使用 Xcode 11.4 / iOS 13.4 對一些復制代碼進行了測試。
List {
ForEach(array.indices, id: \.self) { i in
VStack(spacing: 0) {
Text(self.array[i].title)
.padding(.horizontal)
Text(self.array[i].content)
.padding(.horizontal)
if i != self.array.count - 1 { // don't show for last
Rectangle().fill(Color(UIColor.systemGroupedBackground))
.frame(height: 16) // << fit as you need
}
}.listRowInsets(EdgeInsets()) // << avoid extra space
}
}.listStyle(GroupedListStyle())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.