【问题标题】:How to set the height of the PageTabView如何设置PageTabView的高度
【发布时间】:2022-09-28 01:06:07
【问题描述】:

我想在 pageTabView 中显示一些图像。但是图像大小的图像被压缩了。 如何控制大小。我的图像是从服务器请求的。

struct TextView: View { 
    var body: some View {
        ScrollView(.vertical, showsIndicators: false) {
            VStack(spacing: 0) {
                BannerView()// <- how to set size?
                Text(\"aaaa\")
            }
        }
    }
}

struct BannerView: View {
    var body: some View {
        TabView() {
            ForEach(0..<3) { index in
                VStack{
                    Image(systemName: \"pencil\")
                        .resizable()
                        .scaledToFit()
                        .tag(index)
                }.background(Color.blue)
            }
        }
        .tabViewStyle(PageTabViewStyle())
        .indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always))
    }
} 

    标签: swiftui swiftui-tabview


    【解决方案1】:

    使用.frame(height: yourDesiredHeight)。但是,这将使您的图像保持缩放,就像您使用 .scaleToFit() 一样,它将尝试将所有图像都放入框架中。

    尝试使用.aspectRatio(contentMode: .fill) 填充整个框架。

    【讨论】:

      猜你喜欢
      • 2012-03-01
      • 2014-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      • 2011-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多