0

我有一个相当复杂的视图,我想将它嵌入到 NavigationLink 中,但如果我这样做,所有文本颜色都会变成蓝色。如果视图只是一个图像,我会使用修饰符 renderMode(.original)。但我的视图由多个堆栈、图像、图标和文本组成。是否有一些为什么要防止着色而不将具有正确颜色的修饰符 foregroundColor 单独应用于每个视图?

就是这样的景色

这就是代码:

NavigationLink(destination: BlogView(of: blog)) {
    VStack(spacing: 0) {
        
        HStack {
        URLImage(URL(string: blog.avatarURL)!, content: {
            $0.image
                .resizable()
                .aspectRatio(contentMode: .fill)
                .clipShape(Circle())
        })
            .frame(width: 35, height: 35)
        
        Text(blog.username)
            .font(.custom(R.font.quicksandRegular, size: 16))
        
        Spacer()
        
        Image(systemName: "ellipsis")
            .imageScale(.small)
            .foregroundColor(.darkGray)
        }
        .padding(.vertical, 10)
        .padding(.trailing, 5)
        
        HStack(alignment: .top) {
            VStack(alignment: .leading, spacing: 5) {
                Text(blog.title)
                    .font(.custom(R.font.quicksandRegular, size: 17))
                    .fontWeight(.medium)
                    .foregroundColor(.lightGreen)
            
                Text(blog.text)
                    .font(.custom(R.font.quicksandRegular, size: 14))
                    .lineLimit(3)
            }
        
            Spacer()
        
            URLImage(URL(string: blog.mediaURL)!, content: {
                $0.image
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .clipShape(RoundedRectangle(cornerRadius: 5))
            })
                .frame(width: 120)
                .clipped()
        }
        
        HStack(spacing: 10) {
            Image(systemName: "flame")
                .foregroundColor(.gray)
            Text("\(blog.likeCount)")
        
            Spacer()
        
            Image(systemName: "text.bubble")
                .foregroundColor(.gray)
            Text("\(blog.commentCount)")
        
            Spacer()
        
            Image(systemName: "arrowshape.turn.up.right")
                .foregroundColor(.gray)
            Text("Share")
        }
        .font(.custom(R.font.quicksandRegular, size: 13))
    }
    .padding(.horizontal, 10)
    .background(Color.white)
    .cornerRadius(10)
}
4

1 回答 1

1

.foregroundColor(.primary)在您的Text或查看NavigationLink文档中使用:

按下时触发导航演示的按钮。

这导致我们:

NavigationLink(destination: Text("Destination")) {
    CardView()
}
.buttonStyle(PlainButtonStyle())
于 2020-07-02T15:33:14.690 回答