我正在编写一个 swift
ios
应用程序,我引入了这个 textView
:https://github.com/KennethTsang/GrowingTextView
在我的代码中,我添加了带有一项的 InputToolbar
:
然后包含代码:
let textView = GrowingTextView()
textView.delegate = self
textView.layer.cornerRadius = 4.0
textView.maxLength = 200
textView.maxHeight = 70
textView.trimWhiteSpaceWhenEndEditing = true
textView.placeHolder = "Write a comment..."
textView.placeHolderColor = UIColor(white: 0.8, alpha: 1.0)
textView.placeHolderLeftMargin = 5.0
textView.font = UIFont.systemFontOfSize(15)
inputToolbar.translatesAutoresizingMaskIntoConstraints = false
textView.translatesAutoresizingMaskIntoConstraints = false
textView.returnKeyType = UIReturnKeyType.Send
inputToolbar.addSubview(textView)
let views = ["textView": textView]
let hConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|-8-[textView]-8-|", options: [], metrics: nil, views: views)
let vConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|-8-[textView]-8-|", options: [], metrics: nil, views: views)
inputToolbar.addConstraints(hConstraints)
inputToolbar.addConstraints(vConstraints)
所以现在那里有一个全宽的textview
。我怎样才能在 TextView 旁边添加一个按钮?例如,在 whatsapp 中,textview
旁边有一个小麦克风:
最佳答案
好的,这是将带有附加按钮的 UITextView 添加到 UIToolBar 的方法:
您将 UIView
添加到 UIToolBar
。之后,您可以将 UITextView
添加到 UIToolBar
中的 UIView
。
然后您可以将 UITextView
的自定义类设置为 GrowingTextView
( https://github.com/KennethTsang/GrowingTextView )。
这是我的 Storyboard的屏幕截图。
如果有帮助,请告诉我。
关于ios - 如何在 Swift 中的 TextView 旁边添加一个按钮(以编程方式或在 Storyboard 中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39812161/