ExScrollView 提供了一系列基於 UIScrollView 的擴展類,包括:
ExScrollView:基礎滾動視圖類ExHScroll:水平滾動視圖ExVScroll:垂直滾動視圖ExScroll:通用滾動視圖
func config(
axis: NSLayoutConstraint.Axis? = nil,
indicator: Bool? = nil,
bounces: Bool? = nil,
delegate: UIScrollViewDelegate? = nil
) -> ExScrollView配置滾動視圖的基本屬性:
axis:滾動方向indicator:是否顯示滾動指示器bounces:是否允許回彈效果delegate:滾動視圖代理
func `if`(button bool: Bool, _ _self: (ExScrollView) throws -> Void) rethrows -> Self根據條件執行指定的代碼塊。
專門用於水平滾動的視圖類。
- 強制水平滾動(
.horizontal) - 自動處理內容大小
- 支持鏈式配置
// 基本初始化
init()
// 帶配置的初始化
init(
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil
)
// 帶子視圖的初始化
init(
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil,
@ExViewBuilder builder: () -> [UIView]
)
// 帶變量引用的初始化
init(
_ variable: inout ExScrollView?,
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil
)
// 帶變量引用和子視圖的初始化
init(
_ variable: inout ExScrollView?,
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil,
@ExViewBuilder builder: () -> [UIView]
)專門用於垂直滾動的視圖類。
- 強制垂直滾動(
.vertical) - 自動處理內容大小
- 支持鏈式配置
// 基本初始化
init()
// 帶配置的初始化
init(
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil
)
// 帶子視圖的初始化
init(
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil,
@ExViewBuilder builder: () -> [UIView]
)
// 帶變量引用的初始化
init(
_ variable: inout ExScrollView?,
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil
)
// 帶變量引用和子視圖的初始化
init(
_ variable: inout ExScrollView?,
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil,
@ExViewBuilder builder: () -> [UIView]
)通用滾動視圖類,支持自定義滾動方向。
- 可配置滾動方向
- 完整的配置選項
- 支持子視圖建構器
// 基本初始化
init()
// 帶配置的初始化
init(
axis: NSLayoutConstraint.Axis? = nil,
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil
)
// 帶子視圖的初始化
init(
axis: NSLayoutConstraint.Axis? = nil,
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil,
@ExViewBuilder builder: () -> [UIView]
)
// 帶變量引用的初始化
init(
_ variable: inout ExScrollView?,
axis: NSLayoutConstraint.Axis? = nil,
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil
)
// 帶變量引用和子視圖的初始化
init(
_ variable: inout ExScrollView?,
axis: NSLayoutConstraint.Axis? = nil,
indicator: Bool = true,
bounces: Bool = true,
delegate: UIScrollViewDelegate? = nil,
@ExViewBuilder builder: () -> [UIView]
)let hScroll = ExHScroll(indicator: true, bounces: true) {
someView1
someView2
someView3
}let vScroll = ExVScroll(indicator: false) {
titleLabel
contentView
bottomButton
}let scroll = ExScroll(
axis: .vertical,
indicator: true,
bounces: true
) {
headerView
bodyContent
footerView
}var myScroll: ExScrollView?
ExHScroll(&myScroll, indicator: true) {
// 子視圖
}