[英]iOS - Programatically add a new view to work with my storyboard autolayout viewcontroller
[英]how can I add a button (programatically or in storyboard) right next to my text view in Swift?
我正在編寫一個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
。 如何在文本視圖旁邊添加按鈕? 例如,在whatsapp中, textview
旁邊有一個小麥克風:
好的,這是將帶有附加按鈕的UITextView添加到UIToolBar的方法:
您將UIView
添加到UIToolBar
。 之后,您可以將UITextView
添加到位於UIToolBar
的UIView
中。
然后,您可以將UITextView
的Custom Class設置為GrowingTextView
( https://github.com/KennethTsang/GrowingTextView )。
這是我的故事板的屏幕截圖。
讓我知道是否有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.