[英]how can I add a button (programatically or in storyboard) right next to my text view in Swift?
I'm writing a swift
ios
app and I introduced this textView
: https://github.com/KennethTsang/GrowingTextView 我正在编写一个
swift
ios
应用程序,并介绍了此textView
: https : //github.com/KennethTsang/GrowingTextView
In my code I added InputToolbar
with one item: 在我的代码中,我在
InputToolbar
添加了一项:
and then included the code: 然后包含代码:
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)
so now there's a full-width textview
there. 所以现在那里有一个全角
textview
。 How could I add a button right next to the text view? 如何在文本视图旁边添加按钮? For example in whatsapp there's this small microphone next to the
textview
: 例如,在whatsapp中,
textview
旁边有一个小麦克风:
Ok, here's how you add a UITextView with additional buttons to a UIToolBar: 好的,这是将带有附加按钮的UITextView添加到UIToolBar的方法:
You add a UIView
to the UIToolBar
. 您将
UIView
添加到UIToolBar
。 Afterwards you can add a UITextView
to the UIView
that resides in the UIToolBar
. 之后,您可以将
UITextView
添加到位于UIToolBar
的UIView
中。
Then you can set the Custom Class of the UITextView
to GrowingTextView
( https://github.com/KennethTsang/GrowingTextView ). 然后,您可以将
UITextView
的Custom Class设置为GrowingTextView
( https://github.com/KennethTsang/GrowingTextView )。
Here's a screenshot of my storyboard. 这是我的故事板的屏幕截图。
Let me know if that helps. 让我知道是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.