layer.borderColor
需要CGColor
,而从User defined runtime attributes
中您只能设置UIColor
而不是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
layer
上设置borderColor
和borderWidth
才能看到边框。
Swift 3 & Swift 4:
circle.layer.cornerRadius = 5.0
circle.layer.borderColor = UIColor.red.cgColor
circle.layer.borderWidth = 2.0
在 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
view.layer.borderColor = UIColor.lightGrayColor().CGColor
- iDeveloper