您如何配置收集视图列表单元格以看起来插入圆角?

发布于 2025-02-01 15:20:37 字数 579 浏览 3 评论 0原文

在健康应用中,看来细胞而不是部分以这种方式进行了样式:

“在此处输入图像说明”

我知道的最接近此外观的是将部分设置为插图,

    let listConfiguration = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
    let listLayout = UICollectionViewCompositionalLayout.list(using: listConfiguration)
    collectionView.collectionViewLayout = listLayout

但我不确定在上面的屏幕截图中像在每个单元格中一样的好方法。我假设显示的列表样式收集视图是两个部分,其中有三个总单元格,而不是三个插图分组的部分。

In the Health app, it appears that cells and not sections are styled in this way:

enter image description here

The closest I know of to getting to this appearance is setting the section to be inset grouped

    let listConfiguration = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
    let listLayout = UICollectionViewCompositionalLayout.list(using: listConfiguration)
    collectionView.collectionViewLayout = listLayout

but I'm not sure of a good approach to giving each cell this appearance like in the screenshot above. I'm assuming the list style collection view shown is two sections with three total cells, rather than three inset grouped sections.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

活泼老夫 2025-02-08 15:20:37

将这些行添加到您的收集视图单元格中(单独的单元格设计)。旋转文件,

它将有助于添加边框和半径,您可以根据需要自定义

  override func awakeFromNib() {
            super.awakeFromNib()
            
            self.contentView.layer.cornerRadius = 8.0
            self.contentView.layer.borderWidth = 1.0
            self.contentView.layer.borderColor = UIColor.lightGray.cgColor
            self.contentView.layer.masksToBounds = true
        }

Add these lines into your collection view cell (separate cell design).swift file

it will help in adding the border and radius you can customise as required

  override func awakeFromNib() {
            super.awakeFromNib()
            
            self.contentView.layer.cornerRadius = 8.0
            self.contentView.layer.borderWidth = 1.0
            self.contentView.layer.borderColor = UIColor.lightGray.cgColor
            self.contentView.layer.masksToBounds = true
        }
后eg是否自 2025-02-08 15:20:37

在Swiftui中,我知道您可以做到这一点:

List(.....) { item in 
    Text("What ever you want here").background(Color.white.cornerRadius(10))
}

.cornerradius添加到每个项目或其背景
不确定在uikit

使用uihostingview(或像这样的sth)桥接?

In SwiftUI, I know you can do this:

List(.....) { item in 
    Text("What ever you want here").background(Color.white.cornerRadius(10))
}

Add .cornerRadius to each of the items or its background
Not sure in UIKit
Use UIHostingView(or sth like that) to bridge?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文