1

我试图在下面的这些图片中实现 在此处输入图像描述

在用户编辑 在此处输入图像描述

这是我的代码

    @IBOutlet weak var commentTxtField: MDCMultilineTextField!  // Connected to storyboard

commentTxtField.textView?.delegate = self
        commentTxtField.textView?.frame = CGRect(x: (commentTxtField.textView?.frame.origin.x)!, y: (commentTxtField.textView?.frame.origin.y)!, width: (commentTxtField.textView?.frame.width)!, height: CGFloat(GenUtils.shared.getHeightForPercent(percent: 11.99)))
        commentTxtField.expandsOnOverflow = false
        commentTextFieldController = MDCTextInputControllerOutlinedTextArea(textInput: commentTxtField)
        commentTextFieldController?.placeholderText = "Comment"

        commentTextFieldController?.isFloatingEnabled = true
        commentTextFieldController!.characterCountMax = UInt(maxCharactersCount)
        commentTextFieldController?.characterCountViewMode = UITextField.ViewMode.never
        commentTextFieldController?.activeColor = UIColor.white.withAlphaComponent(0.6)
        commentTextFieldController?.normalColor = UIColor.white.withAlphaComponent(0.2)
        //        emailTextFieldController?.borderFillColor = UIColor.white
        commentTextFieldController?.floatingPlaceholderActiveColor = UIColor(red: 249/255, green: 249/255, blue: 249/255, alpha: 0.54)
        commentTextFieldController?.inlinePlaceholderColor = UIColor.white
        commentTextFieldController?.floatingPlaceholderNormalColor = UIColor(red: 249/255, green: 249/255, blue: 249/255, alpha: 0.54)
        commentTxtField.textColor = UIColor.white
        commentTextFieldController?.inlinePlaceholderFont = UIFont(name:"Avenir-Medium",size:16)

试图设置 textviewframe,但不反映在屏幕上。并且也无法在边界线对齐上获得浮动占位符。我错过了什么?

4

1 回答 1

-1
use **MDCTextField** as below:

class SomeVC: UIViewController, UITextFieldDelegate {

    var textFieldControllerFloating = MDCTextInputControllerUnderline()

    override func viewDidLoad() {
        let textFieldFloating = MDCTextField()
        self.view.addSubview(textFieldFloating)
        //place textfield where you want
        textFieldFloating.placeholder = "Some cool animating placeholder"
        textFieldFloating.delegate = self
        // This will animate the textfield's place holder
        textFieldControllerFloating = MDCTextInputControllerUnderline(textInput: textFieldFloating) 
    }
}

另外,如果您想要一个概述的文本字段,您可以使用“概述”文本字段 https://material.io/develop/ios/components/textfields/

于 2020-03-08T23:06:13.007 回答