How to set the custom border color of UIView programmatically?

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

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

10条回答
  •  执念已碎
    2020-12-23 03:14

    Swift 5.2, UIView+Extension

    extension UIView {
        public func addViewBorder(borderColor:CGColor,borderWith:CGFloat,borderCornerRadius:CGFloat){
            self.layer.borderWidth = borderWith
            self.layer.borderColor = borderColor
            self.layer.cornerRadius = borderCornerRadius
    
        }
    }
    

    You used this extension;

    yourView.addViewBorder(borderColor: #colorLiteral(red: 0.6, green: 0.6, blue: 0.6, alpha: 1), borderWith: 1.0, borderCornerRadius: 20)
    

提交回复
热议问题