macteo / Marklight

Markdown syntax highlighter for iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamic height view

Dan2552 opened this issue · comments

Marklight looks great, fantastic work!

When using a plain UITextView, as I type the size of the view changes to fit the content/text of the view. When enabling Marklight, this behaviour seems to stop. Do you know what could be causing this?

Only constraints for the view in question are (using PureLayout):

view.autoPinEdge(.top, to: .bottom, of: previousView, withOffset: 8)
view.autoPinEdge(toSuperviewEdge: .left, withInset: 8)
view.autoPinEdge(toSuperviewEdge: .right, withInset: 8)

Hello, could you link to a sample project with the two different behaviours?
Thanks

Hello,
the order is important, I've changed the sample project you provided with this code (taken from the provided Marklight Sample project) and the grow seems to work perfectly.

    private func insert(_ text: String) {
    let layoutManager = NSLayoutManager()
    
    let textStorage = MarklightTextStorage()
    // Assign the `UITextView`'s `NSLayoutManager` to the `NSTextStorage` subclass
    textStorage.addLayoutManager(layoutManager)
    
    let textContainer = NSTextContainer()
    layoutManager.addTextContainer(textContainer)
    
    let view = UITextView(frame: CGRect(x: 0, y: 0, width: 100, height: 20), textContainer: textContainer)
    
    // let view = UITextView()
    view.isScrollEnabled = false

    let last = scrollView.subviews.last!
    scrollView.addSubview(view)
    
    view.autoPinEdge(.top, to: .bottom, of: last, withOffset: 8)
    view.autoPinEdge(toSuperviewEdge: .left, withInset: 8)
    view.autoPinEdge(toSuperviewEdge: .right, withInset: 8)
}

simulator screen shot - iphone 8 - 2017-09-20 at 12 35 17

I'm closing the issue as it seems that it was caused by a wrong client-side implementation.