当我给我的视图提供顶部边框时,它无法正常工作。我也在集合视图cellforitematIndexPath
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellRID")
cell.viewForTotalMB.addTopBorderWithColor(color: UIColor(red: 72/255, green: 175/255, blue: 230/255, alpha: 1.0), width: 1)
cell.viewForTotalMB.layer.masksToBounds = false
return cell!
}
我正在使用此扩展名为Borders
extension UIView {
// lbl and txtfld Border line
func addTopBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
border.frame = CGRect(x:0,y: 0, width:self.frame.size.width, height:width)
self.layer.addSublayer(border)
}
}