CCWATextField
您可以使用 CCWATextField 来提升您应用程序的设计和性能。在 iOS 应用中,您可以看到您可以根据自己的喜好自定义多少 CCWATextField 属性。
点击这里下载示例 👇🏻
下载示例
使用 CocoaPods 安装
pod 'CCWATextField', '1.0.1'
使用方法
Storyboard
import CCWATextField
class ViewController: UIViewController {
@IBOutlet weak var ccwaTextField:CCWATextField!
override func viewDidLoad() {
super.viewDidLoad()
ccwaTextField.fieldType = .textField //(Default)
//ccwaTextField.fieldType = .dropDown
//ccwaTextField.fieldType = .dropDownSearch
}
}
Programmatically
import CCWATextField
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let ccwaTextField = CCWATextField()
ccwaTextField.fieldType = .textField //(Default)
//ccwaTextField.fieldType = .dropDown
//ccwaTextField.fieldType = .dropDownSearch
view.addSubview(ccwaTextField)
}
}
Action
这样您可以使用四个动作进行直接操作。
Text-Field
- 编辑开始
- 编辑更改
- 编辑结束
- 触摸内压清除
Drop-Down
- 下拉列表行选择
Drop-Down-Search
- 下拉列表行选择
- 下拉列表搜索更改
//Text-Field
ccwaTextField.editingDidBegin { (text) in
}.editingChanged { (text) in
}.editingDidEnd { (text) in
}.touchUpInsideClear {
}
//Drop-Down
ccwaTextField.dropDownDidSelectRow = { ccwaTextField, index, value in
}
//Drop-Down-Search
ccwaTextField.dropDownDidSelectRow = { ccwaTextField, index, value in
}
ccwaTextField.dropDownSearchEditingChanged = { ccwaTextField, arrCCWADropDownModel, search in
let arrCCWADropDownModel = arrCCWADropDownModel.filter({ $0.title?.localizedCaseInsensitiveContains(search) == true })
return arrCCWADropDownModel
}
属性
属性的默认值
* 不强制设置任何属性的值,你可以根据你的需求设置值。
let ccwaTextField = CCWATextField()
ccwaTextField.fieldType = .dropDown // .textField (Default)
//MARK :- CCWATextField
ccwaTextField.text = ""
ccwaTextField.textColor = .black
ccwaTextField.placeholder = ""
ccwaTextField.animatePlaceholder = false
ccwaTextField.activePlaceholderColor = nil
ccwaTextField.deactivePlaceholderColor = .lightGray
ccwaTextField.activePlacehoderBackGroundColor = .white
ccwaTextField.activeBorderColor = nil
ccwaTextField.deactiveBorderColor = .darkGray
ccwaTextField.activeBorderWidth = 0
ccwaTextField.deactiveBorderWidth = 1
ccwaTextField.activeCornerRadius = 0
ccwaTextField.deactiveCornerRadius = 5
ccwaTextField.activeBackGroundColor = nil
ccwaTextField.deactiveBackGroundColor = .white
ccwaTextField.fontSize = 16
ccwaTextField.fontName = ""
ccwaTextField.activeImageLeftIcon = nil
ccwaTextField.deactiveImageLeftIcon = nil
ccwaTextField.activeImageLeftIconColor = nil
ccwaTextField.deactiveImageLeftIconColor = nil
ccwaTextField.isClearButton = true
ccwaTextField.imageClearButton = nil
ccwaTextField.isSecureText = false
ccwaTextField.activeShadowColor = nil
ccwaTextField.deactiveShadowColor = .clear
ccwaTextField.activeShadowRadius = 0
ccwaTextField.deactiveShadowRadius = 0
ccwaTextField.activeShadowOpacity = 0
ccwaTextField.deactiveShadowOpacity = 1
ccwaTextField.activeShadowOffset = .zero
ccwaTextField.deactiveShadowOffset = .zero
ccwaTextField.doneToolbar = true
//MARK:- CCWADropDown
ccwaTextField.dropDownBackGroundColor = .white
ccwaTextField.dropDownSeperatorLineColor = .lightGray
ccwaTextField.dropDownBorderColor = .lightGray
ccwaTextField.dropDownBorderWidth = 0.5
ccwaTextField.dropDownCornerRadius = 5
ccwaTextField.dropDownShadowColor = .darkGray
ccwaTextField.dropDownShadowRadius = 4
ccwaTextField.dropDownShadowOpacity = 0.5
ccwaTextField.dropDownShadowOffset = CGSize(width: 0, height: 2)
ccwaTextField.dropDownTitleColor = .black
ccwaTextField.dropDownSubtitleColor = .lightGray
ccwaTextField.dropDownTitleFontName = ""
ccwaTextField.dropDownSubtitleFontName = ""
ccwaTextField.dropDownSearchPlaceholder = ""
ccwaTextField.dropDownNoDataMessage = ""
ccwaTextField.dropDownArrowImage = nil
* 你可以使用`tint_color`更改`CCWATextField`的光标颜色和工具栏“完成”的颜色。
ccwaTextField.tintColor = .link
* 要应用主设计,`CCWAOutlineTextField`的主值必须是真。
ccwaTextField.master = true
ccwaTextField.masterValue = CCWATextFieldMaster()
ccwaTextField.dropDownMaster = false
ccwaTextField.dropDownMasterValue = CCWADropDownViewMaster()
所有CCWAOutlineTextField将在活动和非活动时刻与您自定义的方式相同。如果应用了主属性但未设置属性,默认的主属性应用将如下面图像所示。
class func masterValue() -> CCWATextFieldMaster {
//MARK:- Master Property of CCWATextFieldMaster
//Note: The Master-value of the CCWATextField must be true to apply the TextField MasterDesign.
let ccwaTextFieldMaster = CCWATextFieldMaster()
ccwaTextFieldMaster.textColor = .black
ccwaTextFieldMaster.animatePlaceholder = false
ccwaTextFieldMaster.activePlaceholderColor = nil
ccwaTextFieldMaster.deactivePlaceholderColor = .lightGray
ccwaTextFieldMaster.activePlacehoderBackGroundColor = .white
ccwaTextFieldMaster.activeBorderColor = nil
ccwaTextFieldMaster.deactiveBorderColor = .darkGray
ccwaTextFieldMaster.activeBorderWidth = 0
ccwaTextFieldMaster.deactiveBorderWidth = 1
ccwaTextFieldMaster.activeCornerRadius = 0
ccwaTextFieldMaster.deactiveCornerRadius = 5
ccwaTextFieldMaster.activeBackGroundColor = nil
ccwaTextFieldMaster.deactiveBackGroundColor = .white
ccwaTextFieldMaster.fontSize = 16
ccwaTextFieldMaster.fontName = ""
ccwaTextFieldMaster.activeImageLeftIcon = nil
ccwaTextFieldMaster.deactiveImageLeftIcon = nil
ccwaTextFieldMaster.activeImageLeftIconColor = nil
ccwaTextFieldMaster.deactiveImageLeftIconColor = nil
ccwaTextFieldMaster.isClearButton = true
ccwaTextFieldMaster.imageClearButton = nil
ccwaTextFieldMaster.isSecureText = false
ccwaTextFieldMaster.activeShadowColor = nil
ccwaTextFieldMaster.deactiveShadowColor = .clear
ccwaTextFieldMaster.activeShadowRadius = 0
ccwaTextFieldMaster.deactiveShadowRadius = 0
ccwaTextFieldMaster.activeShadowOpacity = 0
ccwaTextFieldMaster.deactiveShadowOpacity = 1
ccwaTextFieldMaster.activeShadowOffset = .zero
ccwaTextFieldMaster.deactiveShadowOffset = .zero
ccwaTextFieldMaster.doneToolbar = true
ccwaTextFieldMaster.tintColor = nil
return ccwaTextFieldMaster
}
class func dropDownMasterValue() -> CCWADropDownViewMaster {
//MARK:- Master Property of CCWADropDownViewMaster
//Note: The Master-value of the CCWATextField must be true to apply the DropDown MasterDesign.
let ccwaDropDownViewMaster = CCWADropDownViewMaster()
ccwaDropDownViewMaster.dropDownBackGroundColor = .white
ccwaDropDownViewMaster.dropDownSeperatorLineColor = .lightGray
ccwaDropDownViewMaster.dropDownBorderColor = .lightGray
ccwaDropDownViewMaster.dropDownBorderWidth = 0.5
ccwaDropDownViewMaster.dropDownCornerRadius = 5
ccwaDropDownViewMaster.dropDownShadowColor = .darkGray
ccwaDropDownViewMaster.dropDownShadowRadius = 4
ccwaDropDownViewMaster.dropDownShadowOpacity = 0.5
ccwaDropDownViewMaster.dropDownShadowOffset = CGSize(width: 0, height: 2)
ccwaDropDownViewMaster.dropDownTitleColor = .black
ccwaDropDownViewMaster.dropDownSubtitleColor = .lightGray
ccwaDropDownViewMaster.dropDownTitleFontName = ""
ccwaDropDownViewMaster.dropDownSubtitleFontName = ""
ccwaDropDownViewMaster.dropDownSearchPlaceholder = ""
ccwaDropDownViewMaster.dropDownNoDataMessage = ""
ccwaDropDownViewMaster.dropDownArrowImage = nil
return ccwaDropDownViewMaster
}
需求
- iOS 12.0
- Xcode 11
- Swift 5.0
可用性
- iPhone & iPad 开发
作者
联系方式
CCWATextField采用MIT许可证发布。有关详细信息,请参见《许可证》。