小编inf*_*ero的帖子

ScrollView 剪切的阴影

有没有办法可以将阴影应用于图像以同时显示在父视图之外?您可以在下面看到一个示例,其中我列出了 aScrollView和中的一些图像HStack。图像/艺术品应用了阴影,但这会被ScrollView.

截图供参考: 在此输入图像描述

ScrollView(.horizontal, showsIndicators: false) {
                                        HStack {
                                            ForEach(stationsFeed.items.sorted(by: { $0.updatedAt > $1.updatedAt }).prefix(15)) { item in

                                                NavigationLink(destination: StationDetailView(station: item)) {
                                                    VStack(alignment: .leading) {

                                                        if item.artwork != nil {
                                                            KFImage(self.artworkURLForStation(item)!)
                                                                .resizable()
                                                                .frame(width: 130, height: 130)
                                                                .scaledToFit()
                                                                .cornerRadius(6)
                                                                .shadow(radius: 5)
                                                        } else {
                                                            RoundedRectangle(cornerRadius: 6)
                                                                .background(Color.purple)
                                                                .shadow(radius: 5)
                                                        }

                                                        Text(item.name)
                                                            .font(.callout)
                                                            .foregroundColor(.primary)

                                                        Text(item.categories.first?.name ?? "N/A")
                                                            .font(.callout)
                                                            .foregroundColor(.secondary)
                                                    }
                                                    .frame(minWidth: 0, maxWidth: 130, alignment: .leading)
                                                }
                                                .buttonStyle(PlainButtonStyle())
                                            }
                                        }
                                    }
Run Code Online (Sandbox Code Playgroud)

ios swift swiftui

10
推荐指数
2
解决办法
2889
查看次数

标签 统计

ios ×1

swift ×1

swiftui ×1