如何在视图中使用共享按钮添加导航栏

时间:2020-07-27 22:44:03

标签: swiftui navigationbar

我正在学习swiftui并尝试创建一个newsapp。当新闻文章打开时,我希望它在底部具有一个导航栏,并带有按钮以将其共享给其他应用程序。已经有此工作代码,但似乎无法使导航栏工作。


struct NewsCell: View {
    
    let news: NewsViewModel
    let image: Image
    
    @State private var isPresented: Bool = false
    
    var body: some View {
        VStack(alignment: .leading, spacing: 10) {
            image
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: UIScreen.main.bounds.width - 30, height: 200, alignment: .center)
                .clipped()
                .cornerRadius(20)
                .shadow(color: .black, radius:5, x: 5, y:5)
            
            Text(news.author)
                .font(.subheadline)
                .padding(10)
                .foregroundColor(.white)
                .background(Color.gray)
                .cornerRadius(10)
            
            Text(news.title)
                .font(.subheadline)
                .foregroundColor(.black)
            
            Text(news.description)
                .font(.caption)
                .foregroundColor(.black)
        }
        .sheet(isPresented: $isPresented) {
            
            NewsArticleWebView(newsUrl: self.news.url)
        }
        .onTapGesture {
            self.isPresented.toggle()
        }
    }
}

0 个答案:

没有答案