To run the example project, clone the repo, and run pod install
from the Example directory first.
and add your project. import MarginScrollView and view create and set scrollView.item
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let view1 = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width * 0.8, height: 100))
view1.backgroundColor = .yellow
let view2 = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width * 0.8, height: 200))
view2.backgroundColor = .red
let view3 = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width * 0.8, height: 300))
view3.backgroundColor = .blue
let view4 = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width * 0.8, height: 70))
view4.backgroundColor = .yellow
let view5 = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width * 0.8, height: 250))
view5.backgroundColor = .red
let view6 = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width * 0.8, height: 100))
view6.backgroundColor = .blue
let scrollView = MarginScrollView()
scrollView.backgroundColor = .black
scrollView.align = .top
view.addSubview(scrollView)
scrollView.items = [view1, view2, view3, view4, view5, view6]
NSLayoutConstraint.activate([
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
scrollView.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
}
}
- Align set align enum value
- top : Top Align
- center : Center Align
- bottom : Bottom Align
-
items Set View Item
-
edgeInsets MarginScrollView's edge Insets
-
decorate inner item decorate. default is DefaultDecorate
public protocol Decorateable {
var itemWidth: CGFloat { get }
var itemSpacing: CGFloat { get }
}
public struct DefaultDecorate : Decorateable {
public var itemWidth: CGFloat = UIScreen.main.bounds.width * 0.8
public var itemSpacing: CGFloat = 15
}
MarginScrollView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MarginScrollView'
Donghyuk Lee, [email protected]
MarginScrollView is available under the MIT license. See the LICENSE file for more info.