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

Linebreak mode in CoreText works differently when comparing to UITextView #7

Open
cyndibaby905 opened this issue Feb 6, 2013 · 3 comments

Comments

@cyndibaby905
Copy link

Thanks for posting your RegexHighlightView! Really helpful.
I read your code, found your are using CoreText to display the stylized content, and make the textColor in UITextView clear to make sure it won't draw any text, so we can reuse UITextView's other behavior such as cursor, text selection.
But there is a problem(I think it should be a bug for CoreText): the linebreak mode in CoreText works a little different to UITextView. I think both CoreText and UITextView are using the same linebreak mode 'LineBreakByWordWrapping', but they define 'word' differently.
Please see the attached image for example.
screenshot
So in some condition, the cursor seems 'off' the content. To resolve this issue, I think we have 3 approaches:

  1. Extend the UITextView, leverage the attributedString related properties(Only works for iOS 6):

    @Property(nonatomic) BOOL allowsEditingTextAttributes NS_AVAILABLE_IOS(6_0); // defaults to NO
    @Property(nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0); // default is nil
    @Property(nonatomic,copy) NSDictionary *typingAttributes NS_AVAILABLE_IOS(6_0); // automatically resets when the selection changes

  2. Extend the UIView, use CoreText to display the content, and add a subView to display the cursor and the selected range.

  3. Set the linebreak mode to LineBreakByCharWrapping. However, the UITextView didn't expose any interfaces to allow us do that, we may have to use some private APIs.

@georgbachmann
Copy link

As I would like to use RegexHighlightView in my project as well and I just discovered the same issue, I'd like to ask if you could explain you possible solutions... I don't get what you mean with possibility one.

Has anybody found a proper solution that might already be working?

@Andrew-Dev
Copy link

I have also noticed this when I used it in my project. I cannot seem to find what is wrong with it.

@TwentyThreeDegrees
Copy link

I've found exactly the same issue - the wrapping is different and so when a line breaks you have unpredictable results - any thoughts about how we could fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants