测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最新发布 | 2015年9月 |
SPM支持 SPM | ✗ |
由 Zachary Clay Smith 维护。
一个围绕 SwiftBinding 库构建的简单 UI 组件库。
github "zacharyclaysmith/SwiftBindingUI"
添加到您的 Cartfilecarthage update
通常,作为一名长期 MVC (即 MVVM、MV* 等) 倡导者,Apple 的 delegate 模式伤害了我的心(以及我的理智)。以下是我开始此框架的原因以及我修改它时的目标的简要概述
通常被称为任何绑定框架的王者,我已经尽力使其尽可能地容易使用。
可绑定属性
text
属性的 BindableValue
。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
}
}
这与 BindableTextField 几乎一样。
可绑定属性
text
属性的 BindableValue
。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
}
}
可绑定属性
image
属性的 BindableValue。
hidden
属性的 BindableValue
。其他属性
UIImage?
,在 imageBinding
的值属性为 nil 时使用。可绑定属性
text
属性的 BindableValue
。hidden
属性的 BindableValue
。可绑定属性
hidden
属性的 BindableValue
。可绑定属性
on
属性的双向绑定 BindableValue
。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
,如果您覆盖了 datasource
或 delegate
属性,将破坏其行为的某些(大多数)方面。
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)?