如何使用背景渐变获取SwiftUI列表和NavigationView?

时间:2019-12-22 14:45:07

标签: ios swift listview swiftui ios-navigationview

滚动列表时,我想将导航栏从大到小缩小。默认情况下,此方法有效,但是,如果我尝试在表格后面添加渐变,它将不再起作用。附加了代码(请尝试取消注释渐变以查看)。如何使它工作?

import SwiftUI

struct BuyView: View {

    let numbers = ["1","2","4","1","2","4","1","2","4","1","2","4","1","2","4","1","2","4"]

    init() {
        UITableView.appearance().backgroundColor = .clear
        UITableViewCell.appearance().backgroundColor = .clear
    }

    var body: some View {
        NavigationView {
            ZStack {
//                LinearGradient(gradient: Gradient(colors: [.gray, .white]), startPoint: .top, endPoint: .bottom)
//                    .edgesIgnoringSafeArea(.all)
                List(numbers, id: \.self) { number in
                  Text(number)
                }.navigationBarTitle("Numbers")
            }
        }
    }
}

struct BuyView_Previews: PreviewProvider {
    static var previews: some View {
        BuyView()
    }
}

enter image description here

enter image description here

0 个答案:

没有答案