Last active
May 12, 2017 13:54
-
-
Save matteocrippa/6b1272118b2e669d24f273cab961bb3a to your computer and use it in GitHub Desktop.
UIStackView add backgroundColor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // fix issue UIStackView that background doesn't work | |
| private var bkgColor: UIColor? | |
| override public var backgroundColor: UIColor? { | |
| get { return bkgColor } | |
| set { | |
| bkgColor = newValue | |
| setNeedsLayout() | |
| } | |
| } | |
| private lazy var backgroundLayer: CAShapeLayer = { | |
| let layer = CAShapeLayer() | |
| self.layer.insertSublayer(layer, at: 0) | |
| return layer | |
| }() | |
| override public func layoutSubviews() { | |
| super.layoutSubviews() | |
| backgroundLayer.path = UIBezierPath(rect: self.bounds).cgPath | |
| backgroundLayer.fillColor = self.backgroundColor?.cgColor | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually you can loose the "super.layoutSubviews()" call. "layoutSubviews()" is a prototype (empty) method.