Reputation:
I have a view I make border with this run time attributes:
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
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
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
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