Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storyboard support #53

Open
Loootus opened this issue May 6, 2019 · 8 comments
Open

Storyboard support #53

Loootus opened this issue May 6, 2019 · 8 comments

Comments

@Loootus
Copy link

Loootus commented May 6, 2019

I can't find one way using Notepad in storyboard.

@ruddfawcett
Copy link
Owner

Hi, you can use a few different approaches to use Notepad with a Storyboard:

  1. Set a custom class of "Notepad" on the UITextView in your Storyboard.
  2. Use an IBOutlet to connected your UITextView to your view controller file, and then extend that UITextView.
  3. Add a Notepad programmatically to a connected view in an .xib file or Storyboard by initializing it and then using someView.addSubview(notepad).

@rivera-ernesto
Copy link
Contributor

  1. Set a custom class of "Notepad" on the UITextView in your Storyboard.

This doesn't seem to work.

@ruddfawcett
Copy link
Owner

Thanks for letting me know, @rivera-ernesto. Are you getting any errors or just no result?

@ruddfawcett ruddfawcett reopened this Apr 1, 2020
@rivera-ernesto
Copy link
Contributor

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().

@DivineDominion
Copy link
Collaborator

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.

@ruddfawcett
Copy link
Owner

ruddfawcett commented Apr 6, 2020

@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.

@ruddfawcett
Copy link
Owner

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.

@rivera-ernesto
Copy link
Contributor

I was trying to "add" functionality to an existing UITextView and noticed that it needs to be initialized with the custom container.

That may be the same reason why Notepads initialized through Storyboards don't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants