我只使用文本和某些修飾符創建了一個按鈕樣式控制元件。但是我希望除此之外還有一個影像,因此我可能必須將其轉換為實際按鈕,除非有一種方法可以在文本元素之外添加影像。

我想要的是第二個“取消”,除此之外還有影像。這是第二個“取消”按鈕的代碼。它只是一個帶有修飾符的 Text 元素,所以我可能無法直接向它添加影像。
Text("Cancel")
.font(.subheadline)
.padding()
.frame(width: 100, height: 20)
.background(Color(red: 0 / 255, green: 94 / 255, blue: 149 / 255))
.foregroundColor(.white)
.padding(5)
.border(Color(red: 0 / 255, green: 94 / 255, blue: 149 / 255), width: 5)
.cornerRadius(15)
我嘗試使用 Button 元素來實作它,但它看起來更大......第一個“取消”按鈕是我嘗試過的輸出。這是代碼:
Button(action: {}) {
HStack {
Text("Cancel").font(.subheadline).foregroundColor(.white)
Image("cross-cancel").foregroundColor(.white)
}
}.padding().background(Color(red: 0 / 255, green: 94 / 255, blue: 149 / 255)).cornerRadius(15)
除了影像,我如何獲得第二個“取消”?
uj5u.com熱心網友回復:
將它們放入HStack并洗掉框架的寬度硬編碼,例如

HStack {
Text("Cancel")
Image(systemName: "xmark.circle")
}
.font(.subheadline)
.padding()
.frame(height: 20)
.background(Color(red: 0 / 255, green: 94 / 255, blue: 149 / 255))
.foregroundColor(.white)
.padding(5)
.border(Color(red: 0 / 255, green: 94 / 255, blue: 149 / 255), width: 5)
.cornerRadius(15)
使用 Xcode 13.4 / iOS 15.5 測驗
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/495433.html
上一篇:部署到Heroku的ASP.NET6API在任何路由上回傳狀態404
下一篇:Firefox中的影片滯后
