Image color does not change

I have a view. I am making a border with these runtime attributes:

enter image description here

The problem is layer.borderColorwhen I set the borderColor my border is gone, but when I don't set the border. Is my color a black frame that I don’t want any ideas?

+4
source share
3 answers

, layer.borderColor CGColor User defined runtime attributes UIColor not CGColor, , borderColor .. black. borderColor, .

Swift 3

yourView.layer.borderColor = UIColor.red.cgColor //set your color here

Swift 2.3

yourView.layer.borderColor = UIColor.redColor().CGColor //set your color here
+3

, @NiravD, borderColor, borderWidth layer, .

Swift 3 Swift 4:

circle.layer.cornerRadius = 5.0
circle.layer.borderColor = UIColor.red.cgColor
circle.layer.borderWidth = 2.0 
0

in Swift 3.0

  @IBOutlet weak var viewMainCell: UIView!

  viewMainCell.layer.shadowOpacity = 0.5
  viewMainCell.layer.shadowRadius = 5
  viewMainCell.layer.shadowColor = UIColor.black.cgColor
  viewMainCell.layer.cornerRadius = 5
  viewMainCell.layer.masksToBounds = false
0
source

Source: https://habr.com/ru/post/1665510/


All Articles