SwiftBindingUI 1.1.3

SwiftBindingUI 1.1.3

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最新发布2015年9月
SPM支持 SPM

Zachary Clay Smith 维护。



  • Zachary Clay Smith

SwiftBindingUI

一个围绕 SwiftBinding 库构建的简单 UI 组件库。

安装

  1. Carthage
    • github "zacharyclaysmith/SwiftBindingUI" 添加到您的 Cartfile
    • 运行 carthage update
  2. CocoaPods
    • pod ‘SwiftBindingUI’
  3. 手动安装
    • 仅从 repo 中拉取并构建它,然后将框架包含到项目中。

目标/哲学

通常,作为一名长期 MVC (即 MVVM、MV* 等) 倡导者,Apple 的 delegate 模式伤害了我的心(以及我的理智)。以下是我开始此框架的原因以及我修改它时的目标的简要概述

  1. 响应式 UI 胜过命令式 UI
    • 我想让我的元素根据它们的数据决定做什么...手动抓取 UI 元素并修改它们是有效的,但完全不可持续。
  2. 减轻基础 UIKit 元素之间的一致性问题。
    • Apple 内置的 UI 元素非常不一致...比较 BindableTextField 和 BindableTextView 的实现以获取良好的想法。

使用方法

BindableTextField

通常被称为任何绑定框架的王者,我已经尽力使其尽可能地容易使用。

可绑定属性

  • textBinding:一个双向绑定到 text 属性的 BindableValue
  • hiddenBinding:一个绑定到 hidden 属性的 BindableValue
import SwiftBinding
import SwiftBindingUI

public class SomeViewController:UIViewController{
    private let _text = BindableValue(value:"Hello")

    @IBOutlet weak var textField:BindableTextField! //NOTE: This is tied to a storyboard/xib element of type BindableTextField.

    override public viewDidLoad(){
        super.viewDidLoad()

        textField.textBinding = _text //EFFECT: textField's text is now set to "Hello"

        _text.value = "Test" //EFFECT textField's text is now "Test"

        //UI EFFECT: changes to the textField in the UI will update the value of _text
    }
}

BindableTextView

这与 BindableTextField 几乎一样。

可绑定属性

  • textBinding:一个双向绑定到 text 属性的 BindableValue
  • hiddenBinding:一个绑定到 hidden 属性的 BindableValue
import SwiftBinding
import SwiftBindingUI

public class SomeViewController:UIViewController{
    private var _text = BindableValue(value:"Hello")

    @IBOutlet weak var textView:BindableTextView! //NOTE: tied to a storyboard element of type BindableTextView.

    override public viewDidLoad(){
        super.viewDidLoad()

        textField.textBinding = _text //EFFECT: textField's text is now set to "Hello"

        _text.value = "Test" //EFFECT textField's text is now "Test"

        //UI EFFECT: changes to the textField in the UI will update the value of _text
    }
}

BindableImageView

可绑定属性

  • imageBinding:一个绑定到 image 属性的 BindableValue
  • hiddenBinding:一个绑定到 hidden 属性的 BindableValue

其他属性

  • nilImage:一个可选的 UIImage?,在 imageBinding 的值属性为 nil 时使用。

BindableLabel

可绑定属性

  • textBinding:一个绑定到 text 属性的 BindableValue
  • hiddenBinding:一个绑定到 hidden 属性的 BindableValue

BindableView

可绑定属性

  • hiddenBinding:一个绑定到 hidden 属性的 BindableValue

可绑定开关

可绑定属性

  • onBinding: 一个绑定到 on 属性的双向绑定 BindableValue
  • hiddenBinding:一个绑定到 hidden 属性的 BindableValue

可绑定按钮

可绑定属性

  • enabledBinding:BindableValue - 双向绑定到 enabled 属性。
  • hiddenBinding:BindableValue - 绑定到 hidden 属性。
  • textBinding:BindableValue- 绑定到按钮标题(使用推荐的方法setTitle`)。注意:目前,这仅适用于“正常”状态,但随着需求的增加将会扩展。
  • imageBinding:BindableValue - 绑定到按钮上的图像(使用推荐的方法 setImage)。注意:目前,这仅适用于“正常”状态,但随着需求的增加将会扩展。

可绑定搜索栏

注意,该搜索栏实现了自己的 UISearchBarDelegate,如果覆盖了代理属性,则会破坏其行为的某些方面。

可绑定属性

  • textBinding: BindableValue
  • hiddenBinding:BindableValue - 绑定到 hidden 属性。

其他属性

  • onBeginEditing: (() -> Void)?
  • onEndEditing: (() -> Void)?
  • onSearchButtonClick: (() -> Void)?
  • onCancelButtonClick: (() -> Void)?

可绑定表格视图

注意,它实现了自己的 `UITableViewDataSource 和 `UITableViewDelegate,如果您覆盖了 datasourcedelegate 属性,将破坏其行为的某些(大多数)方面。

TODO: 这是一个正在进行中的工作 TODO: 更多文档和示例

可绑定属性

  • sections: BindableArray - 这是一个表格分区集合。
  • singleSection:PBindableTableSection - 这是一个便利属性,将 sections 属性暴露为一个单独的分区。我发现我很少使用分区,因此我经常使用这个属性。
  • hiddenBinding:BindableValue - 绑定到 hidden 属性。

其他属性

  • reloadOnSelect:Bool
  • onSelect:((section:PBindableTableSection, index:Int) -> Void)?
  • defaultCellCreator:((sectionIndex:Int, index:Int) -> UITableViewCell)
  • viewForHeaderInSection:((sectionIndex:Int) -> UIView)?
  • viewForFooterInSection:((sectionIndex:Int) -> UIView)?
  • deleteHandler:((indexPath:NSIndexPath) -> Void)?

可绑定收集视图

注意,它实现了自己的 `UICollectionViewDataSource 和 `UICollectionViewDelegate,如果您覆盖了 `datasource` 或 `delegate` 属性,将破坏其行为的某些(大多数)方面。

TODO: 这是一个正在进行中的工作 TODO: 更多文档和示例

可绑定属性

  • sections: BindableArray - 这是一个表格分区集合。
  • singleSection:PBindableTableSection - 这是一个便利属性,将 sections 属性暴露为一个单独的分区。我发现我很少使用分区,因此我经常使用这个属性。
  • hiddenBinding:BindableValue - 绑定到 hidden 属性。
  • showFooterBinding:BindableValue

其他属性

  • reloadOnSelect:Bool
  • onSelect:((section:PBindableTableSection, index:Int) -> Void)?
  • defaultCellCreator:((sectionIndex:Int, index:Int) -> UITableViewCell)
  • viewForHeaderInSection:((sectionIndex:Int) -> UIView)?
  • viewForFooterInSection:((sectionIndex:Int) -> UIView)?
  • deleteHandler:((indexPath:NSIndexPath) -> Void)?