UITextView vs UILabel+ScrollView

左心房为你撑大大i 提交于 2019-12-11 12:48:34

问题


Im working on a an app that requires a view Controller to display a nice amount of hebrew(non-english) text in it.

The text is an AttributedString from a Rich Text File

There are 4 things that I need the view to do.

  1. Smooth Scrolling

  2. Get the range of a word so I can auto-scroll to it (like scrollRangeToVisible)

  3. Change the font smoothly (I'd like to use a UISlider to change the font)

  4. Load quickly

In a sense Im looking for the capabilities of a e-reader just I only need one column and I want it to scroll not page.

Things I've tried and there pros and cons

Regular UITextView & Scrollview Classed as UITextView

PROS:

  • Easy search and auto-scroll
  • Quick load
  • Smooth font changing

CON:

  • Very choppy scrolling

UILabel in a ScrollView

PROS:

  • search and auto-scroll is not easy but manageable
  • Very smooth scrolling

CON:

  • Very choppy font switching
  • Slow loading

The only thing I haven't tried (that I can think of) is CoreText

Is coreText the way to go? I would rather use a UITextView if there as a way to get it to render lots of hebrew (non-english) text better.

Note: I have already tried disabling editing on the UITextView and Selectable.

EDIT 1

-(double)Height{
    [layoutManager glyphRangeForTextContainer:textContainer];
    NSLog(@"HEIGHT = %f",[layoutManager
                          usedRectForTextContainer:textContainer].size.height);
    return [layoutManager
            usedRectForTextContainer:textContainer].size.height;
}

回答1:


I would

  • Create an NSTextStorage(an NSAttributedString) object with the hebrew text.
  • Create NSLayoutManager object, NSTextContainer. Hook them up.
  • Render them onto a custom UIView with a size that you can query from the NSLayoutManager like this.

    Implementing scrollRangeToVisible will be a good task in itself. I would use one of these methods.

    If you only have the character range and need to compute glyph range, one of these methods could help.

    This won't be very easy, but a very good project :)



    来源:https://stackoverflow.com/questions/30651858/uitextview-vs-uilabelscrollview

  • 易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!