Latest0.3.1
Homepagehttps://github.com/LinXunFeng/LXFProtocolTool
LicenseMIT
Platformsios 8.0
Authors

Version
License
Platform

通过协议的方式来方便快捷地实现一些的实用功能,目前功能不多,往后会逐渐增加,喜欢的来个Star吧 : )

对Swift协议不熟悉的同学可以阅读以下两篇文章做下了解:

iOS – Swift 面向协议编程(一)

iOS – Swift 面向协议编程(二)

CocoaPods

LXFProtocolTool 支持CocoaPods:

  • 完全安装
    pod 'LXFProtocolTool'

当然,也可以根据自己的需要安装指定子库

  • Xib加载

    pod 'LXFProtocolTool/LXFNibloadable'
  • 空白视图

    pod 'LXFProtocolTool/EmptyDataSetable'
  • 刷新控件
pod 'LXFProtocolTool/Refreshable'
  • 关联属性
pod 'LXFProtocolTool/AssociatedObjectStore'

Usage

详细使用请打开Example工程查看,以下只做简要使用说明

  • LXFNibloadable

1、View遵守协议LXFNibloadable 不用自己手动遵守,这步跳过

class LXFXibTestView: UIView, LXFNibloadable { }

2、通过静态方法loadFromNib()创建View

let view = LXFXibTestView.loadFromNib()

** 新增tableView和collectionView的与xib相关的方法,如

// 注册 cell
tableView.registerCell(LXFCustomCell.self)
// 注册 headerFooterView
tableView.registerHeaderFooterView(LXFCustomHeaderView.self)

// 其它方法请自己去 LXFNibloadable.swift 中查看吧

  • EmptyDataSetable

1、UIViewControllor或UIView遵守协议 EmptyDataSetable

extension LXFEmptyDemoController: EmptyDataSetable {
}

2、调用方法 updateEmptyDataSet

// 定制方式
// config 不传值时使用默认配置
self.lxf.updateEmptyDataSet(tableView, config: EmptyConfig.noData)

lxf_EmptyDataSet

3、 更新定制

// 更新空白页数据
var config = EmptyConfig.normal
config.tipStr = tipStrArr[randomInt]
config.tipImage = UIImage(named: "tipImg(randomInt)")

self.lxf.updateEmptyDataSet(tableView, config: config)

lxf_EmptyDataSet_update

  • Refreshable

1、遵守协议 Refreshable

class LXFRefreshableController: UIViewController, View, Refreshable {}

2、配置与绑定

// 自定义配置
/* 
initRefresh<T: RefreshControllable>(
    _ vm: T, 
    _ scrollView: UIScrollView, 
    headerConfig: RefreshableHeaderConfig? = nil, 
    footerConfig: RefreshableFooterConfig? = nil, 
    headerAction: (() -> Void)? = nil, footerAction: (() -> Void)? = nil
)
*/
// 注:vm 需要传入一个遵守了 RefreshControllable 协议的对象

lxf.initRefresh(reactor, tableView, headerConfig: RefreshConfig.normalHeader, headerAction: { 
    reactor.action.onNext(.fetchList(true))
}) {
    reactor.action.onNext(.fetchList(false))
}.disposed(by: disposeBag)

3、viewModel 遵守协议

final class LXFRefreshableReactor: Reactor, RefreshControllable {}

遵守协议 RefreshControllable 后便拥有 refreshStatus 属性,可以用来控制刷新控件的状态

self.lxf.refreshStatus.value = .noMoreData
self.lxf.refreshStatus.value = .resetNoMoreData

lxf_EmptyDataSet_update

License

LXFProtocolTool is available under the MIT license. See the LICENSE file for more info.

Author

Latest podspec

{
    "name": "LXFProtocolTool",
    "version": "0.3.1",
    "summary": "LXFProtocolToolu662fu5b9eu7528u7684u534fu8baeu5e94u7528u5de5u5177u5e93",
    "description": "LXFProtocolToolu662fu4f7fu7528Swiftu4e2du7684u534fu8baeu6765u5b9eu73b0u591au79cdu65b9u4fbfu3001u5b9eu7528u7684u5de5u5177u5e93",
    "homepage": "https://github.com/LinXunFeng/LXFProtocolTool",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "LinXunFeng": "[email protected]"
    },
    "source": {
        "git": "https://github.com/LinXunFeng/LXFProtocolTool.git",
        "tag": "0.3.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.0"
    },
    "source_files": "LXFProtocolTool/Classes/**/*.swift",
    "subspecs": [
        {
            "name": "Base",
            "source_files": "LXFProtocolTool/Classes/Base/**/*.{swift}"
        },
        {
            "name": "LXFNibloadable",
            "source_files": "LXFProtocolTool/Classes/LXFNibloadable/**/*.{swift}"
        },
        {
            "name": "Refreshable",
            "source_files": "LXFProtocolTool/Classes/Refreshable/**/*.{swift}",
            "dependencies": {
                "MJRefresh": [],
                "RxSwift": [
                    ">= 4.0.0"
                ],
                "LXFProtocolTool/AssociatedObjectStore": [],
                "LXFProtocolTool/Base": []
            }
        },
        {
            "name": "EmptyDataSetable",
            "source_files": "LXFProtocolTool/Classes/EmptyDataSetable/**/*.{swift}",
            "dependencies": {
                "DZNEmptyDataSet": [
                    ">= 1.8.1"
                ],
                "LXFProtocolTool/AssociatedObjectStore": [],
                "LXFProtocolTool/Base": []
            }
        },
        {
            "name": "AssociatedObjectStore",
            "source_files": "LXFProtocolTool/Classes/AssociatedObjectStore/**/*.{swift}"
        }
    ]
}

Pin It on Pinterest

Share This