CYRTextView icon indicating copy to clipboard operation
CYRTextView copied to clipboard

Support storyboards with initWithCoder:

Open LeoNatan opened this issue 11 years ago • 1 comments

Hello,

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

Thanks, Leo

LeoNatan avatar Jan 19 '14 08:01 LeoNatan

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;
}

illyabusigin avatar Jan 19 '14 20:01 illyabusigin