forked from HabitRPG/habitica-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStackView.swift
42 lines (37 loc) · 1.02 KB
/
StackView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// StackView.swift
// Habitica
//
// Created by Phillip Thelen on 10.04.18.
// Copyright © 2018 HabitRPG Inc. All rights reserved.
//
import UIKit
@IBDesignable
class StackView: UIStackView {
@IBInspectable private var color: UIColor?
override var backgroundColor: UIColor? {
get { return color }
set {
color = newValue
self.setNeedsLayout()
}
}
override var cornerRadius: CGFloat {
get {
backgroundLayer.cornerRadius
}
set {
backgroundLayer.cornerRadius = newValue
}
}
private lazy var backgroundLayer: CAShapeLayer = {
let layer = CAShapeLayer()
self.layer.insertSublayer(layer, at: 0)
return layer
}()
override func layoutSubviews() {
super.layoutSubviews()
backgroundLayer.path = UIBezierPath(roundedRect: self.bounds, cornerRadius: backgroundLayer.cornerRadius).cgPath
backgroundLayer.fillColor = self.backgroundColor?.cgColor
}
}