As I understand, Apple does not provide the source code for UIKit. In order to answer another question, though, I am trying to understand how UITextView
works (or could be made to work) under the hood.
How would I set up a minimal UITextView
myself?
I see from the documentation that it inherits from UIScrollView
so I assume that I would start there.
import UIKit
class MyUITextView: UIScrollView {
// ???
}
Again looking at the text view docs, it looks like I would need to at a minimum implement the init
method and the text
property. (I can ignore all the editing aspects and formatting attributes for now.)
The init
method takes the following form:
init(frame frame: CGRect, textContainer textContainer: NSTextContainer?)
So I would also need a property for an NSTextContainer
. This TextKit
component works together with NSTextStorage
and NSLayoutManager
so I need to work those in somewhere, too. I could set the NSTextStorage
with the text
property but I really don't know how NSLayoutManager
would interact here.
Has anyone (outside of Apple) done this before? Is this a simple enough question to answer here or would the answer be to long?
Update:
This question shows my latest attempt: How to Initialize NSTextStorage with a String in Swift