-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to create a scroll view from any view (#12)
- Loading branch information
1 parent
52fc6a4
commit 7920a14
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// MSScrollView.swift | ||
// MSAutoView | ||
// | ||
// Created by Maher Santina on 8/14/18. | ||
// | ||
|
||
import UIKit | ||
|
||
open class MSScrollView<T: UIView>: UIScrollView { | ||
public var mainView: T? | ||
|
||
func initView(mainView: T) { | ||
self.mainView?.removeFromSuperview() | ||
addSubviewWithConstraints(mainView) | ||
let constraint = NSLayoutConstraint(item: mainView, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1, constant: 0) | ||
addConstraint(constraint) | ||
self.mainView = mainView | ||
} | ||
|
||
} | ||
|
||
public protocol ScrollViewContainable { | ||
associatedtype ScrollViewContainedType: UIView | ||
|
||
var scrollView: MSScrollView<ScrollViewContainedType> { get } | ||
static var scrollView: MSScrollView<ScrollViewContainedType>.Type { get } | ||
} | ||
|
||
extension ScrollViewContainable where Self: UIView { | ||
public var scrollView: MSScrollView<Self> { | ||
let scrollView = MSScrollView<Self>() | ||
scrollView.initView(mainView: self) | ||
return scrollView | ||
} | ||
|
||
public static var scrollView: MSScrollView<Self>.Type { | ||
return MSScrollView<Self>.self | ||
} | ||
} | ||
|
||
extension UIView: ScrollViewContainable { } |
This file contains 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