- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我正在尝试构建一个卡片样式的collectionViewCell,就像这篇文章中看到的那样
https://medium.com/@phillfarrugia/building-a-tinder-esque-card-interface-5afa63c6d3db
经过多次搜索,我发现了一些代码,似乎可以模拟 Collection View 单元格的卡片状外观
cell.contentView.layer.cornerRadius = 8.0
cell.contentView.layer.borderWidth = 1.0
cell.contentView.layer.borderColor = UIColor.clear.cgColor
cell.contentView.layer.masksToBounds = true;
cell.layer.shadowColor = UIColor.lightGray.cgColor
cell.layer.shadowOffset = CGSize(width:0,height: 2.0)
cell.layer.shadowRadius = 2.0
cell.layer.shadowOpacity = 1.0
cell.layer.masksToBounds = false
cell.layer.shadowPath = UIBezierPath(roundedRect:cell.bounds, cornerRadius:cell.contentView.layer.cornerRadius).cgPath
但是,当我运行代码时,我的单元格看起来像这样
看起来一点也不像卡片风格的用户界面。我还可以看到背后的阴影,所以我知道有些事情有点矛盾。我的代码单元并不复杂,但我一直在修改它,但没有看到任何真正的变化,任何人都可以帮助我。
import UIKit
class FeaturedEventCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
public var backgroundImageView: UIImageView = {
let firstImage = UIImageView()
firstImage.clipsToBounds = true
firstImage.translatesAutoresizingMaskIntoConstraints = false
firstImage.contentMode = .scaleToFill
firstImage.image = UIImage(named: "scott_7")
firstImage.layer.cornerRadius = 20
return firstImage
}()
@objc func setupViews(){
setCellShadow()
addSubview(backgroundImageView)
backgroundImageView.snp.makeConstraints { (make) in
make.edges.equalTo(self)
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
最佳答案
阴影绘制在 View 之外,在您的情况下,我认为它们被单元格剪切,即使您将 maskToBounds 设置为 false。
我这样做的方法是使单元格和 contentView 背景清晰,然后添加我自己的另一个 contentView,并在所有侧面插入所需大小的阴影。
然后我将其他 subview 添加到此单元格。
cell.backgroundColor = .clear
cell.contentView.backgroundColor = .clear
let shadowContentView = UIView( frame:cell.contentView.bounds.insetBy( dx:4.0, dy:4.0)
shadowContentView.layer.shadowColor = UIColor.lightGray.cgColor
shadowContentView.layer.shadowOffset = CGSize(width:0.0, height: 2.0)
shadowContentView.layer.shadowRadius = 2.0
shadowContentView.layer.shadowOpacity = 1.0
shadowContentView.layer.cornerRadius = 20.0
shadowContentView.layer.masksToBounds = false
shadowContentView.backgroundColor = .white
let firstImageView = UIImageView()
firstImageView.layer.cornerRadius = 20.0
firstImageView .layer.masksToBounds = false
shadowContentView.addSubView( firstImageView)
关于ios - 卡片式集合ViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51958451/
更新:只是提醒一下,如果有人可以告诉我如何在不使用手势的情况下实现此功能,则有 500 分奖励> 我正在使用 ViewCell 和手势识别器使用以下代码打开选择器。 ViewCell 在左侧有一个标签
我的 xaml 页面上有以下带有绑定(bind)的 listView。我正在从我的 viewModel 将数据绑定(bind)到它。但是这些值没有绑定(bind)到单元格。
我有这个 XAML 代码: Card Selection
我对 JavaFX 非常陌生,想要创建一个自定义 listView,每个 ViewCell 包含 3 个标签和 2 个图像,并且我已在 fxml 文件中定义了它。为了简单起见,我在下面发布了一个仅使用
我希望我的 ListViews ViewCell 中的列都具有相同的大小。它目前设置为自动,最宽的名称应该获胜,所有其他列应该设置为最宽的标签宽度。目前它们每一行的宽度都不同。 ListView It
我已经在谷歌上搜索了一段时间,但没有找到解决方案。 我正在使用一个 nib 文件,它定义了一个我在多个 TableView 上重复使用的 View 单元格。 我的目标是针对不同的手机尺寸采用不同的 V
我建立了一个List<>项目对象的数量,这些对象被用作 ItemsSource到 ListView .在我的 ListView 上 ItemSelected事件,我试图更改该特定项目的元素之一。原始值
我正在尝试更改 listview 上的 ViewCell,但下面的代码对我不起作用:
您好,我使用 Xamarin Forms ListView,我想知道我是否可以基于特定绑定(bind)或在后面的代码中禁用上下文操作。 我为整个应用程序使用一个 GroupedListView,但它会
我在 Xamarin Forms XAML 中有一个 ListView,在这个 ListView 中,我想绘制一个带有 4 个标签和 1 个条目的网格。我的问题是,当我尝试显示 ListView 时,
如何使用 ViewCell 中的 Tapped 操作导航到其他页面? Xmal代码
tl;dr:如何在 Xamarin Forms 中像 iOS 邮件应用一样使用滑动来显示按钮 我正在尝试为类似于 iOS 邮件应用程序或此 https://components.xamarin.com
我有一个带有自定义 ViewCell 的 Xamarin.Forms ListView,其中包含一个带有条目和标签的 StackLayout。我希望在任何时候选择 ViewCell 时条目都能获得焦点
在this question on Xamarin Forums ,Craig Dunn 教授如何创建带框架的单元格。 我想在每个单元格之间添加一个空格。 目前单元格似乎粘在一起,ViewCell 没
我得到了一个带有内部角色系统的应用程序。根据当前角色,用户可以看到更多设置。对于每个设置,我都有一个 ViewCell。因此,就我而言,我想在开始时隐藏特殊设置,并在用户有权这样做时显示它们。 不幸的
我有一个带有按钮的自定义 ViewCell。当我单击此按钮时,我想在显示带有 ViewCell 的 ListView 的 ContentPage 中处理此单击。在 iOS 中,我会使用来自 Cell
我正在使用 ViewCell 在我的表格设置页面中创建行。我有一个设置可以选择浅色或深色主题。
我需要为 ListView View 单元左右滑动手势编写代码(或 XAML)。 向左滑动时,从 ListView (或可观察集合)列表中删除记录并更新 ListView 中剩余的列表项。向右滑动时,
我希望能够更改自定义 ViewCell 上的绑定(bind)属性,并更新 ListView 项 - 但它似乎仅用于初始化 View 并且变化没有反射(reflect)出来。请告诉我我缺少什么! 在这里
我正在 Xamarin.Forms 项目中处理 Accordion ListView。这意味着您可以单击 ListView 中的类别标题,这将展开或折叠其下方的子项。 每个类别标题中有两个图像和一个标
我是一名优秀的程序员,十分优秀!