【问题标题】:SwiftUI: How to get content aligned to top of screen, but keep back buttonSwiftUI:如何让内容与屏幕顶部对齐,但保留后退按钮
【发布时间】:2021-05-10 21:49:48
【问题描述】:

我正在学习 SwiftUI(使用 Swift 5,面向 iOS 13.2)

问)我怎样才能让我的照片(和下面的内容)在缺口区域后面对齐?

到目前为止我在模拟器中得到了什么:

如您所见,我已经了解了如何使用内联导航栏样式。

我想要什么

查看代码:

import SwiftUI

struct DrinkDetail: View {
    
    var drink: Drink
    
    var body: some View {
        List {
            ZStack(alignment: .bottom) {
                Image(drink.imageName)
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                Rectangle()
                    .frame(height: 80.0)
                    .opacity(0.75)
                    .blur(radius: 10)
                
                HStack {
                    Text(drink.name)
                        .font(.largeTitle)
                        .foregroundColor(.white)
                        .padding(8)
                    Spacer()
                }
            }
                .listRowInsets(EdgeInsets())
            
            Text(drink.description)
                .font(.body)
                .foregroundColor(.primary)
                .lineLimit(nil)
                .padding(.bottom, 50.0)
                .lineSpacing(12)
            
            HStack {
                Spacer()
                Button(action: {}) {
                    Text("Order me")
                }
                    .frame(width: 200.0, height: 50.0)
                    .background(Color.blue)
                    .foregroundColor(.white)
                    .cornerRadius(10)
                    
                    
                Spacer()
            }
        }
        .edgesIgnoringSafeArea(.top)
        .navigationBarTitle(Text(""), displayMode: .inline)
    }
}

【问题讨论】:

标签: ios swift xcode swiftui alignment


【解决方案1】:

看起来这根本不可能,尽管我之前看过的教程显示它是可能的。

在另行通知之前,这是唯一的方法:https://stackoverflow.com/a/65523676/12299030

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多