我有一个相当复杂的视图,我想将其嵌入到NavigationLink中,但是如果执行此操作,所有文本颜色将变为蓝色。如果视图只是一个图像,我将使用修饰符renderingMode(.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)
}
答案 0 :(得分:0)
在.foregroundColor(.primary)
上使用Text
或查看NavigationLink
文档:
一个按钮,当按下该按钮时会触发导航演示。
这导致我们去:
NavigationLink(destination: Text("Destination")) {
CardView()
}
.buttonStyle(PlainButtonStyle())