Custom UITextView caret in wrong place - ios

I have implemented the syntax text highlighting as given in the question here (UITextView w/ Syntax Highlighting) - it's a great utility and works well when compared to some non-regex versions (such as the example documented here: http://www.a-coding.com/2012/03/syntax-highlighting-in-ios.html).\
Both implementations, however, give me the same issue. When text in the UITextView is automatically wraps (i.e. is longer than the current view allows) the placement of the caret when editing is incorrect - you attempt to start an edit and the caret appears in the wrong place and when you type the text you enter appears further up the text view than you would expect.
Can anyone give me any pointers as to where the issue might be occurring and how I might be able to begin fixing it? Thanks in advance to any input / suggestions.
You can see here that I have typed XXX at the caret but it has appeared further back along the line incorrectly http://i.stack.imgur.com/zUIhd.png
UPDATE: The issue seems to be firmly within the fact that the custom UITextView wraps (line breaks) in a different place than the standard Apple UITextView - I'm not sure why this is happening or what to do about it though.

Not a super answer but with the release of iOS7 this probably isn't how you'd do this now anyway, see a tutorial such as this one: http://www.raywenderlich.com/50151/text-kit-tutorial

Related

Prevent UIButton showsTouchWhenHighlighted from altering VoiceOver description

Setting showsTouchWhenHighlighted, e.g. via the IB option "Shows Touch On Highlight," on a button without a title will alter the VoiceOver description. After reading the accessibility label, VoiceOver beeps and announces a description of the image. Is there a way to disable this behavior?
Setting the accessibilityContainerType value to UIAccessibilityContainerTypeSemanticGroup works and that's great 👏 but I'm not sure that
this is the goal of this element.
Even if a button my be seen as a container, I understood this instance property dealt with
data-based containers rather. 🤔
I looked into your problem that arouse my curiosity and couldn't find out an appropriate solution with the Apple API unfortunately.
First, I thought that this solution may help but it didn't work as you mentioned in your comment... thanks. 😉
Apparently, when the showsTouchWhenHighlighted property is used, there's an added view inside the button that renders the glow touch ⟹ this is a UIButtonBarPressedIndicator image you can detect thanks to the Debug Hierarchy in Xcode for instance. 👍
This new image seems to put the default value of the accessibility trait property of your button image even if you have already changed it programmatically. 🤯
So, in order to avoid VoiceOver from using the screen recognition and reading out some useless information, I made something very ugly but efficient to reach your goal in the viewDidAppear for instance (see the 'basic operations' sheet of this link):
myButton.subviews.forEach{$0.accessibilityTraits = .none}
Bad hack due to a native problem of implementation or a simple line of code that anyone can understand, this solution removes every possible VoiceOver screen recognition from the button 🥳... and I'm still interested if you can explain a little bit the reason why your solution works, please. 😉
Set accessibilityContainerType = UIAccessibilityContainerTypeSemanticGroup.

Customising the Decimal pad in my app

Swift...
So I've got an existing app and I'm working on its appearance. The current task is customising the decimal pad that pops up when the user hits a textField.
I've looked around on how to make it but it always seems that you have to go into the iPhone/ipad settings and add the custom keyboard.
eg. This StackOverFlow Question
and they all seem to point to this same tutorial..
iOS 8: Creating a Custom Keyboard
My problem is that I don't want the user to have to go into settings.
So the question is....IS THIS POSSIBLE?
The following pic is what I want to use. I have made this in an XIB file through adding a target keyboard which makes the new folder with KeyboardViewController.swift , info.plist and NumPad.xib. Though i think I'm on the wrong track, can someone point me the right way please.
Also anyone know the exact dimensions this view should be.. assuming what I'm asking is in fact possible. Let me know if I'm not being clear enough!
NumPad.xib(pic)
Many many thanks,
Steve
SOLUTION: Thanks to Andrea for correcting my search keywords. It led me to this Stack Question which hopefully sends some others to the correct end of the internet that have mistakes custom keyboard with custom input views!
Sure it is possible without going into settings, but they are called custom input views.
You should look into inputViews here what Apple says about them Custom views for data input.
Basically when the user press a text field instead of loading the usual keyboard it loads an inputView that you specify, pay attention that custom keyboard term is misleading. If you google for tutorial you'll find most probably link like the ones that you found.
For a practical example check this tutorial or this, is a little bit old, but the principle are still the same

How to make Facebook mention like highlighting word in UITextView?

HERE IS SAMPLE IMAGE -->
I'm trying to make text input feature very similar to Facebook's one. The mention that start with # will generate list of my friends name then selecting one will act as something like an object. So deleting the highlighted word will remove whole word in UITextView.
I wonder if that is part of UITextView. Does anyone know how to implement?
Thank you in advance.
I know this is a pretty old question but I've actually made libraries that assist with mentions, when to show the list, does the highlighting etc. It uses attributes on an attributed string to set background.
https://github.com/szweier/SZMentions
https://github.com/szweier/SZMentionsSwift
You'll want to have a look at NSAttributedString. While this class exists in iOS 3.2 or greater, you cannot display it in a UITextView unless you are on iOS 6 or later.

How do I go about building a native iOS rich text editor?

We want a native rich text editor because we are trying to stay away from using Javascript and webviews for this solution.
We've tried many things so far, and we're left with quite a few obstacles that we just can't get around. Let me break it down into questions that I hope you can answer.
I have a UIButton, that says "B" on it, and I want to put it into the 'selected' state when a user sets 'Bold' from using the TextView's long-press gesture on a selection. How do I register for this state change? I tried adding an observer on the textView.attributedText, but it doesn't seem they are changing that dictionary, but instead are updating it. NSDictionary has no way, as far as I know, to add observers on the dictionary's keys. So I'm stuck with noticing this change.
Regarding number 1, I also tried setting the textView's inputDelegate and it seems that the method - (void)textDidChange:(id )textInput never gets called. :( Docs says is should. What did I do wrong?
How do I update the attributedText weight when I hit my bold italic or underline button.
How do I convert my attributed text into HTML?
I saw a few neat libraries for number 4, but I'm still curious what you'd come up with. (Broadens my options). But, I can't really work on number 4 until I figure out how to do the previous 3.
This editor will also need hyperlinks, bulleted lists, and numbered lists, more things I imagine I'll struggle through, but if you could answer the 4 questions above, that will keep me held over for a while. :)
Thanks!
Here is a link to an iOS rich text editor I've been working on.
https://github.com/aryaxt/iOS-Rich-Text-Editor
There is still a lot of work that has to be done, but the basic features are there.
The Apple sample application called 'TextEdit' does much of what you've described and, if not that, would be a very good starting point. Find the sample code with a search in the Organizer.
There is a commercial editor based on the DTCoreText library. I've used that library but not the rich text editor. Look at the Cocoanetics web site. It's not cheap but will save you a ton of work.

Pasting 'tab' to a UITextView

In the simulator I pasted into a UITextView. I wasn't aware I still had some objective-c code on my pasteboard, so the pasted text included multiple lines and some tabs.
I was surprised to see that the text field suddenly became multiline (it looked awful obviously, since the view is tall enough for only 1-2 lines).
I have also experienced in UITextFields that pasting in the same formatted text messes with my implementation of sizeWithFont:constrainedToSize: which I use to size some views correctly.
Can anyone shed some light on what is happening, and whether I need to code around this possibility? On the device itself, does the OS somehow handle the issue? I am also going to try hosting the same piece of text on a website to see if copying and pasting from within the device exhibits the same behavior.
I really hope it is just a limitation of the simulator and copying from an external environment.

Resources