How to set the custom border color of UIView programmatically?

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

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

10条回答
  •  心在旅途
    2020-12-23 03:16

    In Swift 4 you can set the border color and width to UIControls using below code.

    let yourColor : UIColor = UIColor( red: 0.7, green: 0.3, blue:0.1, alpha: 1.0 )
    yourControl.layer.masksToBounds = true
    yourControl.layer.borderColor = yourColor.CGColor
    yourControl.layer.borderWidth = 1.0
    

    < Swift 4, You can set UIView's border width and border color using the below code.

    yourView.layer.borderWidth = 1
    
    yourView.layer.borderColor = UIColor.red.cgColor
    

提交回复
热议问题