如何向UICollectionViewCell添加阴影和拐角半径,包括页眉和页脚

问题描述

我正在使用iOS中的UICollectionCompositionalLayouts构建应用程序,我想重新创建以下单元格

Collection View Cell with Shadow including Header and Footer

该单元格的所有侧面都有阴影和圆角,包括页眉和页脚,就好像它是该单元格的一部分一样。当我尝试在UICollectionViewCell中重新创建此外观时,只能将Shadow添加到标题中,其他所有内容都将被忽略。以下是我的手机

My Collection View Cell

无论我如何设置组成该部分的单个集合视图单元,阴影都永远不会出现,并且该单元似乎不会像第一个图像那样连接。

这是我用来设置单元格的代码

标题的自定义代码

class HeaderWorkoutOfDay:UICollectionReusableView {


let mainView = UIView()

static let reuseIdentifier = String(describing: self)

static let elementKind = String(describing: self)


let programmeNameButton = UIButton(type: .system)

let workoutNameLabel = UILabel()

override init(frame: CGRect) {
    super.init(frame: frame)
    
    addSubview(mainView)
    
    mainView.snp.makeConstraints { (view) in
        view.top.left.bottom.right.equalToSuperview()
    }
    
    
    mainView.addSubview(programmeNameButton)
    mainView.addSubview(workoutNameLabel)
    costumizeViews()
    setupConstraints()
    
    
    
    
    
}

required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

private func costumizeViews(){
    
    programmeNameButton.titleLabel?.font = UIFont.systemFont(ofSize: 20,weight: .regular)
    programmeNameButton.contentHorizontalAlignment = .left
    
    workoutNameLabel.font = UIFont.systemFont(ofSize: 25,weight: .bold)
    
    self.mainView.layer.maskedCorners = [.layerMinXMinYCorner,.layerMaxXMinYCorner]
    
    self.mainView.layer.cornerRadius = 14
    self.mainView.layer.masksToBounds = true
    self.mainView.backgroundColor = UIColor.white
    
    self.layer.shadowOpacity = 1.0
    self.layer.shadowColor = UIColor(red: 200,green: 200,blue: 200).cgColor
    self.layer.shadowRadius = 10
    self.layer.masksToBounds = false
    self.layer.shadowOffset = CGSize(width: 0.0,height: 0.0)
    
    
}

private func setupConstraints(){
    
    programmeNameButton.snp.makeConstraints { (button) in
        button.left.top.right.equalToSuperview().offset(8)
        button.bottom.equalTo(workoutNameLabel.snp.top).offset(-8)
    }
    
    
    workoutNameLabel.snp.makeConstraints { (label) in
        label.left.equalToSuperview().offset(8)
        label.top.equalTo(programmeNameButton.snp.bottom).offset(8)
        label.bottom.right.equalToSuperview().offset(-8)
    }
    
}

}

我对单个单元格和页脚使用的设置相同,也是UICollectionReusableView

如何重新创建第一张图片的外观?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...