ICInputAccessory 2.0.1

ICInputAccessory 2.0.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2019年2月
SPM支持 SPM

bcylinRichard Lee 维护。




  • bcylin 和 trisix

ICInputAccessory

iCook 应用 中使用的自定义文本框。

Build Status Carthage compatible CocoaPods Compatible Platform Swift 4.1

KeyboardDismissTextField

  • 在输入辅助视图中拥有一个按钮来关闭键盘的文本框。

TokenField

  • 一个水平滚动的 UI,用于分组输入文本。
  • 轻松添加、选择和删除标记。
  • 可自定义图标和颜色。
  • 支持 Storyboard。

ICTokenField

OptionPickerControl

  • 一个易于使用的 UIControl,显示包含给定选项的 UIPickerView

需求

IC输入辅助 iOS Xcode Swift
~> 1.0.0 8.0+ 7.2 Swift 2.1.1
~> 1.1.0 8.0+ 7.3 Swift 2.2
~> 1.2.0 8.0+ 8.0 Swift 2.3
~> 1.3.0 8.0+ 8.0 Swift 3.0
~> 1.4.0 8.0+ 8.3 Swift 3.1
~> 1.5.0 8.0+ 9.3 Swift 4.1
~> 2.0.0 8.0+ 10.0 Swift 4.1

安装

使用Carthage

创建一个包含以下指定的Cartfile,然后运行carthage update ICInputAccessory。按照说明将框架添加到iOS项目中。

github "polydice/ICInputAccessory"

使用CocoaPods

IC输入辅助支持子规格。创建一个包含以下指定的Podfile,然后运行pod install

platform :ios, '8.0'
use_frameworks!

pod 'ICInputAccessory/TokenField'
pod 'ICInputAccessory/KeyboardDismissTextField'

使用Git子模块

git submodule add -b master [email protected]:polydice/ICInputAccessory.git Dependencies/ICInputAccessory
  • 所有需要的文件都位于目录中。将这些文件添加到您的项目中。
  • 或者,将ICInputAccessory.xcodeproj拖拽到您的应用程序项目中作为子项目。在应用程序目标的构建阶段设置中添加ICInputAccessory-iOS目标依赖

使用方法

KeyboardDismissTextField

let textField = KeyboardDismissTextField(frame: rect)

TokenField

let tokenField = TokenField(frame: rect)
tokenField.delegate = self as? TokenFieldDelegate

完成标记的字符

/// Characters that complete a new token, defaults are whitespace and commas.
public var delimiters: [String]

标记

/// Texts of each created token.
public var texts: [String] { get }

/// Creates a token with the current input text.
public func completeCurrentInputText()

/// Removes the input text and all displayed tokens.
public func resetTokens()

UI 个性化定制

/// The image on the left of text field.
public var icon: UIImage? { get set }

/// The placeholder with the default color and font.
public var placeholder: String? { get set }

/// The placeholder with customized attributes.
public var attributedPlaceholder: NSAttributedString? { get set }

/// Customized attributes for tokens in the normal state, e.g. .font and .foregroundColor.
public var normalTokenAttributes: [NSAttributedStringKey : NSObject]? { get set }

/// Customized attributes for tokens in the highlighted state.
public var highlightedTokenAttributes: [NSAttributedStringKey : NSObject]? { get set }

Storyboard 中的可定制属性

@IBInspectable var icon: UIImage?
@IBInspectable var placeholder: String?
@IBInspectable var textColor: UIColor?
@IBInspectable var cornerRadius: CGFloat

有关更多详情,请参阅 Example/CustomizedTokenField.swift

TokenFieldDelegate

TokenField 目前会通知代理以下事件

@objc optional func tokenFieldDidBeginEditing(_ tokenField: TokenField)
@objc optional func tokenFieldDidEndEditing(_ tokenField: TokenField)
@objc optional func tokenFieldWillReturn(_ tokenField: TokenField)
@objc optional func tokenField(_ tokenField: TokenField, didChangeInputText text: String)
@objc optional func tokenField(_ tokenField: TokenField, shouldCompleteText text: String) -> Bool
@objc optional func tokenField(_ tokenField: TokenField, didCompleteText text: String)
@objc optional func tokenField(_ tokenField: TokenField, didDeleteText text: String, atIndex index: Int)

显示的定界符字符串可以通过以下方式进行定制

@objc optional func tokenField(_ tokenField: TokenField, subsequentDelimiterForCompletedText text: String) -> String

OptionPickerControl

一个符合 OptionDescriptive 协议的示例类型

extension String: OptionDescriptive {

  var title: String {
    return self
  }

  static var titleForOptionalValue: String {
    return "(optional)"
  }

}

要通过 CGRect.zero 初始化 OptionPickerControl 并将它添加到视图层

let optionPicker = OptionPickerControl<String>()
optionPicker.options = [.optional, Option("Option 1"), Option("Option 2")]
optionPicker.addTarget(self, action: #selector(didChangeOption(_:)), for: .valueChanged)
view.addSubview(optionPicker)

显示 UIPickerView

optionPicker.becomeFirstResponder()

文档

开发

  • 通过在项目根目录运行以下命令设置依赖

    make bootstrap
    
  • 打开 ICInputAccessory.xcworkspace 并使用 Example 方案运行演示应用程序。

  • 有关构建和测试的更多任务,请参阅

    rake -T
    

贡献

感谢您对这个项目的贡献兴趣。我们很高兴听到您的想法!

请fork这个仓库,创建一个名为 feature/some-new-feature 的分支,向我们发送一个请求以改善该项目。

联系

Twitter Join the chat at https://gitter.im/polydice/ICInputAccessory

许可协议

版权(c)2016 Polydice, Inc.

ICInputAccessory 采用MIT许可协议发布。详细信息请见 LICENSE