MarginScrollView
截图
第一视图和第二视图
示例
要运行示例项目,首先克隆仓库,然后从Example目录中运行pod install
。
并将您的项目添加进去。导入MarginScrollView并创建视图设置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)
])
}
}
属性
- 对齐集对齐枚举值
- top : 顶部对齐
- center : 居中对齐
- bottom : 底部对齐
-
items 设置视图项
-
edgeInsets 边距MarginScrollView的边距
-
decorate 内部项装饰。默认为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 可以通过 CocoaPods 使用。要安装它,只需将以下行添加到您的 Podfile 中
pod 'MarginScrollView'
作者
outofcoding, [email protected]
许可证
MarginScrollView 可在 MIT 许可下使用。更多信息请参阅 LICENSE 文件。