ZStack{
RoundedRectangle(cornerRadius: 8).foregroundColor(.red).scaledToFit()//.frame(width: 200, height: 25)
HStack{
Image(systemName: "tag.fill").foregroundColor(.white)
Text("Tickets Not Available").font(.headline).foregroundColor(.white).fixedSize(horizontal: true, vertical: false)
}
}.scaledToFit()
如您所见,我的视图放置在zstack中,因此圆角矩形可以作为文本视图的背景。我已经尝试了许多不同的方法,例如将.scaledtofit放在哪里,它每次都给我带来古怪的结果。
这是您要执行的操作(注意Image.resizable):
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack{
RoundedRectangle(cornerRadius: 8).foregroundColor(.blue)
HStack{
Image(systemName: "tag.fill").resizable().padding(4).foregroundColor(.white).scaledToFit()
Text("Get Tickets").font(.headline).foregroundColor(.white)
}
}.fixedSize()
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句