我需要在我的快速项目中使用占位符实现大纲文本字段,例如 Material UI。我尝试用谷歌搜索相同但找不到任何东西。有谁知道如何快速实现它?参考图片:
问问题
8630 次
3 回答
5
使用这个吊舱,您可以获得相同的设计
- 使用情节
UIView
提要并设置约束 - 制作作为子类的类
UIView
并导入 podMaterialComponents.MaterialTextFields
和MaterialComponents.MaterialTextFields_ColorThemer
类 CustomOutlinedTxtField: UIView {
private var textFieldControllerFloating: MDCTextInputControllerOutlined!
var textField: MDCTextField!
@IBInspectable var placeHolder: String!
@IBInspectable var value: String!
@IBInspectable var primaryColor: UIColor! = .purple
override open func draw(_ rect: CGRect) {
super.draw(rect)
textField.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height)
}
open override func awakeFromNib() {
super.awakeFromNib()
setUpProperty()
}
func setUpProperty() {
//Change this properties to change the propperties of text
textField = MDCTextField(frame: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height))
textField.placeholder = placeHolder
textField.text = value
//Change this properties to change the colors of border around text
textFieldControllerFloating = MDCTextInputControllerOutlined(textInput: textField)
textFieldControllerFloating.activeColor = primaryColor
textFieldControllerFloating.floatingPlaceholderActiveColor = primaryColor
textFieldControllerFloating.normalColor = UIColor.lightGray
textFieldControllerFloating.inlinePlaceholderColor = UIColor.lightGray
//Change this font to make borderRect bigger
textFieldControllerFloating.inlinePlaceholderFont = UIFont.systemFont(ofSize: 14)
textFieldControllerFloating.textInsets(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
self.addSubview(textField)
}
}
- 将该自定义类分配给
UIView
结果
于 2020-02-20T12:54:11.393 回答
1
您可以使用材料组件:-
它将如下所示。
https://material.io/components/text-fields/
Github 存储库 - https://github.com/material-components/material-components-ios
于 2020-02-20T12:44:04.130 回答
1
你也可以试试这个框架SkyFloatingLabelTextField
,TextFieldEffects
或者TweeTextField
https://github.com/Skyscanner/SkyFloatingLabelTextField
于 2020-02-20T12:54:02.710 回答