簡體   English   中英

如何在Swift的文本視圖旁邊添加按鈕(以編程方式或在情節提要中)?

[英]how can I add a button (programatically or in storyboard) right next to my text view in Swift?

我正在編寫一個swift ios應用程序,並介紹了此textViewhttps : //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添加到位於UIToolBarUIView中。

然后,您可以將UITextView的Custom Class設置為GrowingTextViewhttps://github.com/KennethTsang/GrowingTextView )。

這是我的故事板的屏幕截圖。

UIToolBar內具有其他按鈕的GrowingTextView

讓我知道是否有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM