gpt4 book ai didi

ios - 在 UITableViewCell 中设置 UIRectCorner 的位置

转载 作者:行者123 更新时间:2023-11-28 16:06:29 30 4
gpt4 key购买 nike

我想在表格单元格内的 View 的底部和左上角应用一些圆角。我在 UIView 上做了这个扩展:

extension UIView {
func round(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
}

但我不确定在我的 View 中究竟在哪里调用它才能正确显示它。现在我在我的自定义单元格的 layoutSubviews() 中调用了它,但是当我启动我的应用程序时,左下角部分不是圆形的,只有在单元格离开屏幕并重新绘制之后。

UITableViewCell 中设置圆角的最佳位置应该是什么?

编辑:

这是带有层次结构的屏幕截图: enter image description here

代码:

override func layoutSubviews() {
super.layoutSubviews()

configureView()
}

func configureView() {
bgView.layer.cornerRadius = 3.0
period.round([.bottomLeft, .topLeft], radius: 3.0)
bgView.layer.masksToBounds = false
period.layer.masksToBounds = false
bgView.layer.shadowColor = UIColor.black.withAlphaComponent(0.2).cgColor
bgView.layer.shadowOffset = CGSize(width: 0, height: 0)
bgView.layer.shadowOpacity = 0.8
}

编辑 2:

enter image description here

最佳答案

这是我的 CustomTableViewCell

import UIKit

class CustomTableViewCell: UITableViewCell {

@IBOutlet weak var period: UIView!
@IBOutlet weak var bgView: UIView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
bgView.layer.cornerRadius = 5.0

// you might not be doing this earlier
bgView.clipsToBounds = true

period.round([.bottomLeft,.topLeft], radius: 5.0)

}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

}

我的 TableView 数据源方法

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "CustomTableViewCell") as! CustomTableViewCell
return cell
}

enter image description here

我的 View 层次结构

enter image description here

关于ios - 在 UITableViewCell 中设置 UIRectCorner 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40203724/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com