How to set the custom border color of UIView programmatically?

后端 未结 10 483
情书的邮戳
情书的邮戳 2020-12-23 02:29

I am trying to set the custom border color of UIView programmatically in Swift.

10条回答
  •  攒了一身酷
    2020-12-23 03:08

    We can create method for it. Simply use it.

    public func createBorderForView(color: UIColor, radius: CGFloat, width: CGFloat = 0.7) {
        self.layer.borderWidth = width
        self.layer.cornerRadius = radius
        self.layer.shouldRasterize = false
        self.layer.rasterizationScale = 2
        self.clipsToBounds = true
        self.layer.masksToBounds = true
        let cgColor: CGColor = color.cgColor
        self.layer.borderColor = cgColor
    }
    

提交回复
热议问题