swift label only border left

前端 未结 6 1332
[愿得一人]
[愿得一人] 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:49

    Swift 4 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.bounds.width, height: thickness)
    
                case UIRectEdge.bottom:
                 border.frame = CGRect(x: 0, y: self.bounds.height - thickness,  width: self.bounds.width, height: thickness)
    
                case UIRectEdge.left:
                 border.frame = CGRect(x: 0, y: 0,  width: thickness, height: self.bounds.height)
    
                case UIRectEdge.right:
                 border.frame = CGRect(x: self.bounds.width - thickness, y: 0,  width: thickness, height: self.bounds.height)
    
                default:
                 break
            }
            border.backgroundColor = color.cgColor;
            self.addSublayer(border)
        }
    }
    

提交回复
热议问题