swift label only border left

前端 未结 6 1267
[愿得一人]
[愿得一人] 2021-02-03 12:13

good morning together,

i have a tableview like this:

Example: in cell one i have got an red text label on the right side. left from it i include an image like a

6条回答
  •  忘了有多久
    2021-02-03 12:54

    Swift 3 version:

    extension CALayer {
    
        func addBorder(edge: UIRectEdge, color: UIColor, thickness: CGFloat) {
    
            let border = CALayer()
    
            switch edge {
            case UIRectEdge.top:
                border.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: thickness)
                break
            case UIRectEdge.bottom:
                border.frame = CGRect(x: 0, y: self.frame.height - thickness, width: self.frame.width, height: thickness)
                break
            case UIRectEdge.left:
                border.frame = CGRect(x: 0, y: 0, width: thickness, height: self.frame.height)
                break
            case UIRectEdge.right:
                border.frame = CGRect(x: self.frame.width - thickness, y: 0, width: thickness, height: self.frame.height)
                break
            default:
                break
            }
    
            border.backgroundColor = color.cgColor;
    
            self.addSublayer(border)
        }
    
    }
    

    Or use IBDesignable (see answer below)

提交回复
热议问题