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

Support storyboards with initWithCoder: #4

Open
LeoNatan opened this issue Jan 19, 2014 · 1 comment
Open

Support storyboards with initWithCoder: #4

LeoNatan opened this issue Jan 19, 2014 · 1 comment

Comments

@LeoNatan
Copy link

Hello,

Cool view! You should add support for storyboards by implementing initWithCoder:

Thanks,
Leo

@illyabusigin
Copy link
Owner

Hi Leo,

Thanks for the feature suggestion! I took a stab at this but ran into some issues since the text storage is already created when calling [super initWithCoder:]. I've posted my attempt below. Suggestions or pull requests welcome!

  • Illya
- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];

    if (self)
    {
        CYRTextStorage *textStorage = [CYRTextStorage new];
        CYRLayoutManager *layoutManager = [CYRLayoutManager new];

        self.lineNumberLayoutManager = layoutManager;

        //  Wrap text to the text view's frame
        self.textContainer.widthTracksTextView = YES;

        [layoutManager addTextContainer:self.textContainer];

        [textStorage removeLayoutManager:textStorage.layoutManagers.firstObject];
        [textStorage addLayoutManager:layoutManager];

        self.syntaxTextStorage = textStorage;

        self.contentMode = UIViewContentModeRedraw; // causes drawRect: to be called on frame resizing and device rotation

        [self _commonSetup];
    }

    return self;
}

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

2 participants