Skip to content

Commit 7c1a080

Browse files
author
Gürhan Yerlikaya
committed
added init methods for access stackview’s properties
1 parent a181dc7 commit 7c1a080

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

ScrollableStackView/Classes/ScrollableStackView.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ import UIKit
1616
@objc open var stackView: UIStackView!
1717
@objc @IBInspectable open var spacing: CGFloat = 8
1818

19-
override public func didMoveToSuperview() {
20-
super.didMoveToSuperview()
21-
22-
setupUI()
19+
required public init?(coder aDecoder: NSCoder) {
20+
fatalError("init(coder:) has not been implemented")
2321
}
2422

25-
func setupUI() {
26-
self.translatesAutoresizingMaskIntoConstraints = false
27-
clipsToBounds = true
28-
23+
override public init(frame: CGRect) {
24+
super.init(frame: frame)
25+
2926
// ScrollView
3027
scrollView = UIScrollView(frame: self.frame)
3128
scrollView.translatesAutoresizingMaskIntoConstraints = false
@@ -38,6 +35,17 @@ import UIKit
3835
stackView.spacing = spacing
3936
stackView.distribution = .equalSpacing
4037
scrollView.addSubview(stackView)
38+
}
39+
40+
override public func didMoveToSuperview() {
41+
super.didMoveToSuperview()
42+
43+
setupUI()
44+
}
45+
46+
func setupUI() {
47+
self.translatesAutoresizingMaskIntoConstraints = false
48+
clipsToBounds = true
4149

4250
self.setNeedsUpdateConstraints() // Bootstrap auto layout
4351
}

0 commit comments

Comments
 (0)