user7155952
user7155952

Reputation:

View border Color not changing

I have a view I make border with this run time attributes:

enter image description here

The problem is layer.borderColor when I set borderColor my border is gone but when I don't set border Color I have a black border which I don't want any ideas?

Upvotes: 7

Views: 10375

Answers (3)

Amul4608
Amul4608

Reputation: 1448

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

Upvotes: 0

Rbar
Rbar

Reputation: 3918

In addition to what @NiravD suggested, you need to set both borderColor and the borderWidth on the view's layer to see the border.

Swift 3 & Swift 4:

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

Upvotes: 3

Nirav D
Nirav D

Reputation: 72410

You are facing this issue because layer.borderColor want CGColor and from User defined runtime attributes you can only set UIColor not CGColor, when you don't set the color it will take default borderColor and i.e black color. To set borderColor you need to set it programmatically like this.

Swift 3

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

Swift 2.3 or lower

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

Upvotes: 9

Related Questions