[英]Corner Radius of both HStack and TextField not updating
這是我的內容視圖的代碼。 如您所見,我已經嘗試過使用 HStack 來包含 TextField,也嘗試過單獨使用 TextField。 角半徑與灰色搜索矩形沒有任何關系 - 邊緣仍然是完美的矩形。
@State var searchText = ""
var body: some View {
ZStack {
//function that's the content argument to ZStack
Color((.systemGreen))
VStack {
Text("App")
.font(.largeTitle)
.foregroundColor(Color.white)
//HStack {
TextField("Searchstring", text: $searchText)
.padding()
.background(Color(.systemGray6))
.padding()
.cornerRadius(12)
//}
// .padding()
// .background(Color(.systemGray6))
// .padding(.horizontal)
// .cornerRadius(12)
}
}
}
}
這就是預覽的樣子,在所有情況下:角半徑無法在預覽中顯示
問題在這里:
.padding() /// 1.
.background(Color(.systemGray6)) /// 2.
.padding() /// 3.
.cornerRadius(12) /// 4.
padding
padding
后應用background
background
之后添加另一個padding
padding
頂部應用另一個cornerRadius
因此,圓角的是padding
,而不是background
。
相反,您希望在background
之后立即應用cornerRadius
。
struct ContentView: View {
@State var searchText = ""
var body: some View {
ZStack {
//function that's the content argument to ZStack
Color((.systemGreen))
VStack {
Text("App")
.font(.largeTitle)
.foregroundColor(Color.white)
TextField("Searchstring", text: $searchText)
.padding()
.background(Color(.systemGray6))
.cornerRadius(12) /// corner radius immediately after the background
.padding() /// extra padding outside the background
}
}
}
}
結果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.