在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:xmartlabs/Eureka开源软件地址:https://github.com/xmartlabs/Eureka开源编程语言:Swift 99.7%开源软件介绍:Made with OverviewContentsFor more information look at our blog post that introduces Eureka. Requirements (for latest release)
Example projectYou can clone and run the Example project to see examples of most of Eureka's features. UsageHow to create a formBy extending import Eureka
class MyFormViewController: FormViewController {
override func viewDidLoad() {
super.viewDidLoad()
form +++ Section("Section1")
<<< TextRow(){ row in
row.title = "Text Row"
row.placeholder = "Enter text here"
}
<<< PhoneRow(){
$0.title = "Phone Row"
$0.placeholder = "And numbers here"
}
+++ Section("Section2")
<<< DateRow(){
$0.title = "Date Row"
$0.value = Date(timeIntervalSinceReferenceDate: 0)
}
}
} In the example we create two sections with standard rows, the result is this: You could create a form by just setting up the Configuring the keyboard navigation accesoryTo change the behaviour of this you should set the navigation options of your controller. The
The default value is To enable smooth scrolling to off-screen rows, enable it via the To set the amount of space between the keyboard and the highlighted row following a navigation event, set the class MyFormViewController: FormViewController {
override func viewDidLoad() {
super.viewDidLoad()
form = ...
// Enables the navigation accessory and stops navigation when a disabled row is encountered
navigationOptions = RowNavigationOptions.Enabled.union(.StopDisabledRow)
// Enables smooth scrolling on navigation to off-screen rows
animateScroll = true
// Leaves 20pt of space between the keyboard and the highlighted row after scrolling to an off screen row
rowKeyboardSpacing = 20
}
} If you want to change the whole navigation accessory view, you will have to override the Getting row valuesThe // Get the value of a single row
let row: TextRow? = form.rowBy(tag: "MyRowTag")
let value = row.value
// Get the value of all rows which have a Tag assigned
// The dictionary contains the 'rowTag':value pairs.
let valuesDictionary = form.values() OperatorsEureka includes custom operators to make form creation easy: +++ Add a sectionform +++ Section()
// Chain it to add multiple Sections
form +++ Section("First Section") +++ Section("Another Section")
// Or use it with rows and get a blank section for free
form +++ TextRow()
+++ TextRow() // Each row will be on a separate section <<< Insert a rowform +++ Section()
<<< TextRow()
<<< DateRow()
// Or implicitly create the Section
form +++ TextRow()
<<< DateRow() += Append an array// Append Sections into a Form
form += [Section("A"), Section("B"), Section("C")]
// Append Rows into a Section
section += [TextRow(), DateRow()] Using the callbacksEureka includes callbacks to change the appearance and behavior of a row. Understanding Row and CellA Here is an example: let row = SwitchRow("SwitchRow") { row in // initializer
row.title = "The title"
}.onChange { row in
row.title = (row.value ?? false) ? "The title expands when on" : "The title"
row.updateCell()
}.cellSetup { cell, row in
cell.backgroundColor = .lightGray
}.cellUpdate { cell, row in
cell.textLabel?.font = .italicSystemFont(ofSize: 18.0)
} Callbacks list
Section Header and FooterYou can set a title String titleSection("Title")
Section(header: "Title", footer: "Footer Title")
Section(footer: "Footer Title") Custom viewYou can use a Custom View from a Section() { section in
var header = HeaderFooterView<MyHeaderNibFile>(.nibFile(name: "MyHeaderNibFile", bundle: nil))
// Will be called every time the header appears on screen
header.onSetupView = { view, _ in
// Commonly used to setup texts inside the view
// Don't change the view hierarchy or size here!
}
section.header = header
} Or a custom Section(){ section in
var header = HeaderFooterView<MyCustomUIView>(.class)
header.height = {100}
header.onSetupView = { view, _ in
view.backgroundColor = .red
}
section.header = header
} Or just build the view with a Callback Section(){ section in
section.header = {
var header = HeaderFooterView<UIView>(.callback({
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
view.backgroundColor = .red
return view
}))
header.height = { 100 }
return header
}()
} Dynamically hide and show rows (or sections)In this case we are hiding and showing whole sections. To accomplish this each row has a Hiding using a function conditionUsing the Condition.function([String], (Form)->Bool) The array of form +++ Section()
<<< SwitchRow("switchRowTag"){
$0.title = "Show message"
}
<<< LabelRow(){
$0.hidden = Condition.function(["switchRowTag"], { form in
return !((form.rowBy(tag: "switchRowTag") as? SwitchRow)?.value ?? false)
})
$0.title = "Switch is on!"
} public enum Condition {
case function([String], (Form)->Bool)
case predicate(NSPredicate)
} Hiding using an NSPredicateThe $0.hidden = Condition.predicate(NSPredicate(format: "$switchTag == false")) And we can write it even shorter since $0.hidden = "$switchTag == false" Note: we will substitute the value of the row whose tag is 'switchTag' instead of '$switchTag' For all of this to work, all of the implicated rows must have a tag as the tag will identify them. We can also hide a row by doing: $0.hidden = true as Not setting the If you manually set the hidden (or disabled) condition after the form has been displayed you may have to call SectionsFor sections this works just the same. That means we can set up section Disabling rowsTo disable rows, each row has an Note that if you want to disable a row permanently you can also set List SectionsTo display a list of options, Eureka includes a special section called form +++ SelectableSection<ListCheckRow<String>>("Where do you live", selectionType: .singleSelection(enableDeselection: true))
let continents = ["Africa", "Antarctica", "Asia", "Australia", "Europe", "North America", "South America"]
for option in continents {
form.last! <<< ListCheckRow<String>(option){ listRow in
listRow.title = option
listRow.selectableValue = option
listRow.value = nil
}
} What kind of rows can be used?To create such a section you have to create a row that conforms the public protocol SelectableRowType : RowType {
var selectableValue : Value? { get set }
} This Getting the selected rowsTo easily get the selected row/s of a Grouping options in sectionsAdditionally you can setup list of options to be grouped by sections using following properties of
Multivalued SectionsEureka supports multiple values for a certain field (such as telephone numbers in a contact) by using Multivalued sections. It allows us to easily create insertable, deletable and reorderable sections. How to create a multivalued sectionIn order to create a multivalued section we have to use let's dive into a code example... form +++
MultivaluedSection(multivaluedOptions: [.Reorder, .Insert, .Delete],
header: "Multivalued TextField",
footer: ".Insert adds a 'Add Item' (Add New Tag) button row as last cell.") {
$0.addButtonProvider = { section in
return ButtonRow(){
$0.title = "Add New Tag"
}
}
$0.multivaluedRowToInsertAt = { index in
return
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论