123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- // FieldsRow.swift
- // Eureka ( https://github.com/xmartlabs/Eureka )
- //
- // Copyright (c) 2016 Xmartlabs SRL ( http://xmartlabs.com )
- //
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- import Foundation
- import UIKit
- open class TextCell: _FieldCell<String>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func setup() {
- super.setup()
- textField.autocorrectionType = .default
- textField.autocapitalizationType = .sentences
- textField.keyboardType = .default
- }
- }
- open class IntCell: _FieldCell<Int>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func setup() {
- super.setup()
- textField.autocorrectionType = .default
- textField.autocapitalizationType = .none
- textField.keyboardType = .numberPad
- }
- }
- open class PhoneCell: _FieldCell<String>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func setup() {
- super.setup()
- textField.keyboardType = .phonePad
- if #available(iOS 10,*) {
- textField.textContentType = .telephoneNumber
- }
- }
- }
- open class NameCell: _FieldCell<String>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func setup() {
- super.setup()
- textField.autocorrectionType = .no
- textField.autocapitalizationType = .words
- textField.keyboardType = .asciiCapable
- if #available(iOS 10,*) {
- textField.textContentType = .name
- }
- }
- }
- open class EmailCell: _FieldCell<String>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func setup() {
- super.setup()
- textField.autocorrectionType = .no
- textField.autocapitalizationType = .none
- textField.keyboardType = .emailAddress
- if #available(iOS 10,*) {
- textField.textContentType = .emailAddress
- }
- }
- }
- open class PasswordCell: _FieldCell<String>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func setup() {
- super.setup()
- textField.autocorrectionType = .no
- textField.autocapitalizationType = .none
- textField.keyboardType = .asciiCapable
- textField.isSecureTextEntry = true
- if #available(iOS 11,*) {
- textField.textContentType = .password
- }
- }
- }
- open class DecimalCell: _FieldCell<Double>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func setup() {
- super.setup()
- textField.autocorrectionType = .no
- textField.keyboardType = .decimalPad
- }
- }
- open class URLCell: _FieldCell<URL>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func setup() {
- super.setup()
- textField.autocorrectionType = .no
- textField.autocapitalizationType = .none
- textField.keyboardType = .URL
- if #available(iOS 10,*) {
- textField.textContentType = .URL
- }
- }
- }
- open class TwitterCell: _FieldCell<String>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func setup() {
- super.setup()
- textField.autocorrectionType = .no
- textField.autocapitalizationType = .none
- textField.keyboardType = .twitter
- }
- }
- open class AccountCell: _FieldCell<String>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func setup() {
- super.setup()
- textField.autocorrectionType = .no
- textField.autocapitalizationType = .none
- textField.keyboardType = .asciiCapable
- if #available(iOS 11,*) {
- textField.textContentType = .username
- }
- }
- }
- open class ZipCodeCell: _FieldCell<String>, CellType {
- required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- }
- required public init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- open override func update() {
- super.update()
- textField.autocorrectionType = .no
- textField.autocapitalizationType = .allCharacters
- textField.keyboardType = .numbersAndPunctuation
- if #available(iOS 10,*) {
- textField.textContentType = .postalCode
- }
- }
- }
- open class _TextRow: FieldRow<TextCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- }
- }
- open class _IntRow: FieldRow<IntCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- let numberFormatter = NumberFormatter()
- numberFormatter.locale = Locale.current
- numberFormatter.numberStyle = .decimal
- numberFormatter.minimumFractionDigits = 0
- formatter = numberFormatter
- }
- }
- open class _PhoneRow: FieldRow<PhoneCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- }
- }
- open class _NameRow: FieldRow<NameCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- }
- }
- open class _EmailRow: FieldRow<EmailCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- }
- }
- open class _PasswordRow: FieldRow<PasswordCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- }
- }
- open class _DecimalRow: FieldRow<DecimalCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- let numberFormatter = NumberFormatter()
- numberFormatter.locale = Locale.current
- numberFormatter.numberStyle = .decimal
- numberFormatter.minimumFractionDigits = 2
- formatter = numberFormatter
- }
- }
- open class _URLRow: FieldRow<URLCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- }
- }
- open class _TwitterRow: FieldRow<TwitterCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- }
- }
- open class _AccountRow: FieldRow<AccountCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- }
- }
- open class _ZipCodeRow: FieldRow<ZipCodeCell> {
- public required init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A String valued row where the user can enter arbitrary text.
- public final class TextRow: _TextRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A String valued row where the user can enter names. Biggest difference to TextRow is that it autocapitalization is set to Words.
- public final class NameRow: _NameRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A String valued row where the user can enter secure text.
- public final class PasswordRow: _PasswordRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A String valued row where the user can enter an email address.
- public final class EmailRow: _EmailRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A String valued row where the user can enter a twitter username.
- public final class TwitterRow: _TwitterRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A String valued row where the user can enter a simple account username.
- public final class AccountRow: _AccountRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A String valued row where the user can enter a zip code.
- public final class ZipCodeRow: _ZipCodeRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A row where the user can enter an integer number.
- public final class IntRow: _IntRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A row where the user can enter a decimal number.
- public final class DecimalRow: _DecimalRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A row where the user can enter an URL. The value of this row will be a URL.
- public final class URLRow: _URLRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
- /// A String valued row where the user can enter a phone number.
- public final class PhoneRow: _PhoneRow, RowType {
- required public init(tag: String?) {
- super.init(tag: tag)
- }
- }
|