Open Loootus opened 5 years ago
Hi, you can use a few different approaches to use Notepad with a Storyboard:
someView.addSubview(notepad).
- Set a custom class of "Notepad" on the UITextView in your Storyboard.
This doesn't seem to work.
Thanks for letting me know, @rivera-ernesto. Are you getting any errors or just no result?
No results. I've been fighting with it yesterday. Is seems that Storage
methods never get called.
I've been trying to set the theme in viewDidLoad
(self.notepad.storage.theme = Theme("one-dark")
). For that I had to change storage
visibility to public private(set) var storage: Storage = Storage()
.
Yeah, you're right: when you use Storyboards/Xibs, the init(withCoder:)
variant is called. Since theme configuration is only supported by passing in theme info to the initializer, you effectively cannot customize the theme at all.
I would hide the knowledge, tbh, and change Notepad
:
public class Notepad: UITextView {
var storage: Storage = Storage()
public var theme: Theme {
get { return storage.theme }
set { storage.theme = newValue }
}
// ...
}
That would be a more stable API that exposes theme configuration on the base object, while hiding knowledge about the implementation in Storage.
@DivineDominion is correct, init(withCoder:)
is called with Storyboards, so you'll have to use something like they suggested. An obvious oversight on my part, unfortunately. I think at one time I was imagining that the theme could be an IBInspectable/IBDesignable
... but alas I forgot...
Looks like this is addressed in your PR #57.
Oops, my bad — misread #57. Let me think on this, even though I saw your PR with programmatic themes #59, I think there should be a drag/drop way to use Notepad. Perhaps with IBInspectables, etc. I'll play around with it when I get a chance.
I was trying to "add" functionality to an existing UITextView
and noticed that it needs to be init
ialized with the custom container.
That may be the same reason why Notepad
s initialized through Storyboards don't work.
I can't find one way using Notepad in storyboard.