Skip to content

Commit

Permalink
added init methods for access stackview’s properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Gürhan Yerlikaya committed Dec 19, 2016
1 parent a181dc7 commit 7c1a080
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions ScrollableStackView/Classes/ScrollableStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ import UIKit
@objc open var stackView: UIStackView!
@objc @IBInspectable open var spacing: CGFloat = 8

override public func didMoveToSuperview() {
super.didMoveToSuperview()

setupUI()
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func setupUI() {
self.translatesAutoresizingMaskIntoConstraints = false
clipsToBounds = true

override public init(frame: CGRect) {
super.init(frame: frame)

// ScrollView
scrollView = UIScrollView(frame: self.frame)
scrollView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -38,6 +35,17 @@ import UIKit
stackView.spacing = spacing
stackView.distribution = .equalSpacing
scrollView.addSubview(stackView)
}

override public func didMoveToSuperview() {
super.didMoveToSuperview()

setupUI()
}

func setupUI() {
self.translatesAutoresizingMaskIntoConstraints = false
clipsToBounds = true

self.setNeedsUpdateConstraints() // Bootstrap auto layout
}
Expand Down

0 comments on commit 7c1a080

Please sign in to comment.