ICInputAccessory
在 iCook 应用 中使用的自定义文本框。
KeyboardDismissTextField
- 在输入辅助视图中拥有一个按钮来关闭键盘的文本框。
TokenField
- 一个水平滚动的 UI,用于分组输入文本。
- 轻松添加、选择和删除标记。
- 可自定义图标和颜色。
- 支持 Storyboard。
OptionPickerControl
- 一个易于使用的
UIControl
,显示包含给定选项的UIPickerView
。
需求
IC输入辅助 | iOS | Xcode | Swift |
---|---|---|---|
~> 1.0.0 |
8.0+ | 7.2 | |
~> 1.1.0 |
8.0+ | 7.3 | |
~> 1.2.0 |
8.0+ | 8.0 | |
~> 1.3.0 |
8.0+ | 8.0 | |
~> 1.4.0 |
8.0+ | 8.3 | |
~> 1.5.0 |
8.0+ | 9.3 | |
~> 2.0.0 |
8.0+ | 10.0 |
安装
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
的分支,向我们发送一个请求以改善该项目。
联系
许可协议
版权(c)2016 Polydice, Inc.
ICInputAccessory 采用MIT许可协议发布。详细信息请见 LICENSE。