gpt4 book ai didi

ios - 如何将自定义 NSTextStorage 设置为从 Storyboard 创建的 UITextView 对象?

转载 作者:行者123 更新时间:2023-12-04 19:32:45 24 4
gpt4 key购买 nike

我想设置一个自定义NSTextStorageUITextView从 Storyboard 创建的对象。如果真的需要,我可以考虑 UITextView 的子类化.

(我知道如果我从代码中创建了 UITextView 对象,我将能够使用 init(frame: CGRect, textContainer: NSTextContainer?) 构造函数。)

swift 更可取。

最佳答案

我可以通过添加 UITextView 来完成此操作 subview 到 UIView从 Storyboard实例化的包装器子类。然后,您可以在返回框的 textView 实例的 View Controller 上添加一个 getter,以便您可以将自己分配为委托(delegate)、访问属性等...

就像是

class ViewController: UIViewController, UITextViewDelegate {

@IBOutlet private weak var textViewBox: TextViewBox! // connected in storyboard

var textView: UITextView! {
return textViewBox?.textView
}

override func viewDidLoad() {
super.viewDidLoad()

textView?.delegate = self
}
}

关于ios - 如何将自定义 NSTextStorage 设置为从 Storyboard 创建的 UITextView 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45569579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com