TTTAttributedLabel "Read More >" tail truncation with several attributes possible? - ios

TTTAttributedLabel support a custom truncation string via truncationTokenString as well as truncationTokenStringAttributes.
However, I am wanting to go a bit further and set several string attributes on the truncation string, including different fonts and colours. This is what I am trying to achieve:
The arrow at the end can be achieved using a font icon, so I was thinking of the following string:
#"… Read More >"
'HORIZONTAL ELLIPSIS' (U+2026) + Read More + > character from a font.
Unfortunately TTTAttributedLabel doesn't allow me to set the ranges for various attributes.
Does anyone have a good solution for this or will have have to do it manually and basically calculate the string as it can be drawn on two lines including the #"… Read More >" string.
Thanks!

I'm just answering my own question in case anyone stumbled onto it needing the same functionality.
At the time of posting the question TTTAttributedLabel only supported setting attributes on the whole truncation token string.
I added functionality for NSAttributedString support (for which you can specify ranges, which was missing from the plan NSDictionary with attributes approach) and submitted a pull request. It hasn't yet been merged into the main branch for TTTAttributedLabel, but in case anyone's in need of the same functionality you can find the PR here:
https://github.com/runmad/TTTAttributedLabel/commit/628de3f9cb688eb58fffdbb6e7ff81fa0d8b7f4a

Related

Eggplant : How to read text with special characters like ' _ etc

I am trying to read a text in a given rectangle using readText() function.
The function works correctly except when it has to read some text which has special characters like ' _ & etc.
I tried using validCharacters with readText() function. But it didn't help.
Code -
put ReadText((287,125,810,164),validCharacters:"_-'.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890") into Login
I tried working with character collections. But that doesn't seem to be right because the text trying to pick is a dynamic text combination of numbers alphabets and a special character. So one cannot create a library of character collection of every alphabet (a-z, A-Z), numbers(0-9) and special characters.
Example of text trying to read:
Login_Userid1_1, Login'Userid1_1
So how do I read such text correctly
Debugging OCR is a bit of an imprecise science. EggPlant has a lot of OCR Parameters to tweak. When designing test cases it's best to try use other mechanisms to gather information whenever possible. ReadText() should be considered a last resort when more reliable methods are unavailable. When I've used it I've often needed to do a lot of trial and error to find the right set of settings, and SearchRectangle to get consistent results. Without seeing exactly what images you are trying to read text from it's difficult to impossible to troubleshoot where the issue might be.
One thing that does stand out to me is that you're trying to read strings that may contain underscores. ReadText() has an optional property IgnoreUnderscores which treats underscores as spaces. By default this property is set to ON. It defaults to ON because some OCR engines have problems identifying underscore characters consistently.
If you want to have ReadText() handle underscores you'll want to explicitly set this property to OFF.
ReadText(rect, validCharacters:chars, ignoreUnderscores:OFF)

Excluding place holder texts from localisations

When I design a cell layout I usually assign a sample text, e.g. 'John Appleseed' to a 'name' label so I can easily see where the field is on the layout and check the composition. Otherwise there is an empty label on a white background. Obviously this text does not need to be translated as it will be always replaced by another value at runtime.
Is there any property I can set in the Object Inspector to exclude this text from .strings / XLIFF file? Translators usually charge per word, so I don't want to send those texts for translation.
For the time being I use '~' prefix and then remove those texts using a Ruby script, but I was wondering whether there is an easier way to do it.
Unfortunately, if you are using ibtool (and you do not really have an alternative) you cannot exclude words directly.
What you can do, is to edit the XLIFF file after you export it and add the attribute translate="no" on the strings you want to exclude. You should make sure that your translators use a XLIFF-compatible tool to translate.
But, imho, this is not any better than your way.
Also see question 1, question 2 and ibtool's manual.

character entity not showing in google search

I'm using   on my page, encoding is UTF-8, no BOM. Works pretty well even in other search engine, but the excerpt, Google is showing for my page contains a visible
 
code. Is there something, I can do against it?
Apparently Google does not recognize the   entity reference; you didn’t provide a URL, but it was rather simple to confirm the observation, searching with "hairsp" (with quotes).
The way around this bug is to use the numeric character reference &#x200a or the character U+200A HAIR SPACE itself.
You might also consider using other methods for creating added spacing, such as the padding properties in CSS. They are more flexible than the fixed-width spaces.

Retrieve text from pdf in iOS, using zachron iphonepdf?

I'm using the same zachrone iphonepdf but I did not get the text. My text view shows nothing. What's the problem?
Here is my code:
NSString *text=convertPDF(#"Course.pdf");
texview.text=text;
But I did not get anything in text view?
The text extractor zachron / pdfiphone (I assume you meant that one) is extremely naive and makes very many assumptions.
It ignores the PDF file structure and, therefore completely ignores whether the data it inspects is still used in the current revision.
It ignores encryption and therefore will fail completely for many documents with usage restrictions.
It completely ignores font encodings and implicitely assumes an ASCII'ish one --- this is fairly often true in small PDFs with English text only and not embedded fonts; otherwise the result can be anything.
... many many more assumptions ...
Unless one only has to deal with very simple documents and the extracted text is not really necessary for the functionality of one's code, I would propose using different code for text extraction.

How does one change the text on the clipboard without altering the format information?

Another clipboard question:
When text is put onto the clipboard, it frequently goes in multiple ways, usually with and without formatting information. What I want to know is this -- how do you change the text on the clipboard without altering the formatting. In other words, I want to change the text side of things, but keep the formatting exactly the same.
This is again for my "TextScrubber" application where I want to remove line breaks from the text on the clipboard, but I don't want to alter the format info about that text.
I'm hoping that I don't have to "brute force" it by iterating over all the formats present, storing each, and then reinserting them after the text has been scrubbed.
I think the "brute force" is precisely what you'll have to do - according to MSDN Win32 API there is no way to do otherwise.
Yep, Nick. I think in this case you're going to be stuck with the solution already suggested. The clipboard is one area that hasn't really gotten much attention in the enhancement department throughout the years. That is probably because it does need to be simple, ubiquitous, and functional.
Why not simply load from the clipboard, change the text, and write back to the clipboard?
Maybe something simple like Sergey Tkachenko's TBin Clipboard: http://delphi32.org/vcl/2889/
Eric Rosenberger's answer to "Can not round trip html format to clipboard" might also be of use.

Resources