When I am giving Top border to my view it is not properly working. Also I am using it in collection view 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!
}
I am using this extension for 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)
}
}