Code Monkey home page Code Monkey logo

Comments (8)

DivineDominion avatar DivineDominion commented on May 24, 2024 2

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.

from notepad.

ruddfawcett avatar ruddfawcett commented on May 24, 2024 1

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.

from notepad.

ruddfawcett avatar ruddfawcett commented on May 24, 2024

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

from notepad.

rivera-ernesto avatar rivera-ernesto commented on May 24, 2024
  1. Set a custom class of "Notepad" on the UITextView in your Storyboard.

This doesn't seem to work.

from notepad.

ruddfawcett avatar ruddfawcett commented on May 24, 2024

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

from notepad.

rivera-ernesto avatar rivera-ernesto commented on May 24, 2024

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

from notepad.

ruddfawcett avatar ruddfawcett commented on May 24, 2024

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

from notepad.

rivera-ernesto avatar rivera-ernesto commented on May 24, 2024

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.

from notepad.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.