I'm using custom NSCell in NSTableView similar to:
http://www.martinkahr.com/2007/05/04/nscell-image-and-text-sample/
I wish to display text with many clickable URL.
can any body throw me in tight direction?
I was trying to do something like:
http://snippets.aktagon.com/snippets/358-How-to-make-a-clickable-link-inside-a-NSTextField-and-Cocoa
but it change NSCell in link, I wish to change only some parts of text into links.
thanks for any help
The line that reads
NSRange range = NSMakeRange(0, [attrString length]);
is picking the part of the text that will be changed into a link. This code makes it the whole string. To make it a subset of the string, just set the range appropriately.
Related
I have something like a diagramming UWP application where each shape has an RichEditBox. The problem is, that I loose the formatting when the text is empty.
For Example:
Change the text to bold: EditBox.Document.Selection.CharacterFormat.Bold = FormatEffect.On.
Delete all text
Get the text via "EditBox.Document.GetText(GetTextFormat.FormatRtf, out text);
=> The result is just an empty string, not valid RTF document at all. This is a problem in my scenario. Is there an approach to solve it? I think RichEditBox should always provide a valid RTF document.
I have a UITextView and would like to offer the user a chance to mark text within this text view.
I have tried to use UITextPosition but it is not precise enough and I do not know which text has being marked.
UITextPosition *tapPos = [textView closestPositionToPoint:touchPosition];
UITextRange *wr = [textView.tokenizer rangeEnclosingPosition:touchPosition withGranularity:UITextGranularityWord inDirection:UITextLayoutDirectionRight];
This solution also does not solve the next step of dragging along the words in order to mark more than one word.
I thought of something like the makers of Lightly did.
http://lightlyapp.com
I need to analyze text of my Word document, and create bookmarks on range of text my analyzer has detected (almost like a grammar checker).
I don't want use Find() utility, because my needs are too specific.
Explanations
For that,
1/ Retrieve Document plain text
I Retrieve Plain text of the main story of my document :
String plainText = ActiveDocument.Range().Text;
2/ Analyze plain text and get results
I send it to my analyzer tool which return a collection of marker with position :
For example, if I wanted to detected the pattern "my pattern" in the document text, analyzer could return a marker as { pattern : "my marker", start: 5, end : 14 }, where "start" and "end" are the character indexes of the pattern in the plain text sent.
3/ Display results in Document
I create bookmark from theses markers
For previously example, it woold be :
// init a new range and collapse it
Word.Range range = activeDocument.Range(); range.Collapse(WdCollapseStart);
// move character-by-character in the "formatted" text
range.MoveStart(WdUnits.Character, Marker.start ); # Marker.start=5
//set length (end)
range.setRange(range.Start,range.Start+(Marker.End-Marker.Start)); #Marker.end=14
4/ Results
4.1 Global Result
Everything is OK when Document Main Story Contains Text, links, lists, titles :
Ranges are well positionned, Plain Text indexes correlate with formatted text indexes.
4.2 Arrays Issue
When a document contains an array, Ranges are bad positionned a few characters : Plain Text indexes correlate not exactly with formatted text indexes.
I found the reason of this issue (It was explained in others forums) : this is due to non printing char(7), which is a cell delimiter added in plain text. We can handle these chars to calculate position range and everything is OK !
4.3 Issue for Content Controls, Table of contents, Sections and others
When a document contains theses elements, Ranges are also bad positionned a few characters.
Others non printing appears in plain text but I don't understand what it means and how deal with to calculate position range.
By displaying Word element markers with "Developer ribbon > creation mode", we see 2 markers per elements : shifting plain text indexes by 2*elements resolve issues. It's seems OK.
4.4 Issue with Endpaper
I don't know how we says "page de garde" (french) in english, I think it's "endpaper" : this is the first page with specific header, footer and content controls :)
When a document contains an Endpaper, Ranges are also bad positionned a few characters.
But this time, there are not non printing marker in the plain text.
Other info, when I display word element markers with "Developer ribbon > creation mode", I see endpaper markers.
Questions
How detect Endpaper in Word Document Range ?
How understand Plain Text indexes don't always correlate with formatted text indexes, in function of Word document elements which contains ?
XML nodes manipulation would be a more reliable alternative for that? If yes, could you give me good examples to manage bookmars or others in current document with XML Api ?
Others ressources
I found similar issues :
Correlate Range.Text to Range.Start and Range.End
http://www.vbaexpress.com/forum/showthread.php?36710-Strange-character-on-table-range-text
I hope my explanations are clear and you can help me to understand what is wrong or show me a best way to do that ?
Thanks, really.
It's not really pretty but you can try to remove the unwanted characters by Regex. For example to remove the \a letters (it has code 7):
string j = new string(new char[] { (char)7 });
plainText = Regex.Replace(plainText,string.Format("[{0}]", j), "");
Now you have to identify the other 'evil' characters and add them to the char array. If it works you will get a string whose length corresponds with the number of Characters in your document. Probably you have to adapt this code by experimenting. (I was not sure which language you are using - I supposed C#.)
Update
Another idea (if it is applicable to your analyzer tool):
Break your problem down to single paragraphs:
foreach(Word.Paragraph pg in activeDocument.Paragraphs)
{
Word.Range range = pg.Range();
string text = range.Text;
// your stuff here
}
With this paragraph range objects and the contained text strings you do the same as you tried to do with the whole document object and its text - just paragraph by paragraph. All these paragraphs are 'addressable' by ranges and Move operations as you already do it. I suppose that the problematic characters are outside or at the end of the paragraphs so they don't influence the character counting inside these paragraphs.
As I can't reproduce what you call endpaper I can't validate it. Besides I don't know if special text ranges as page headers and tables of content are covered by paragraphs. But at least you can reduce your problem to smaller ranges. I think it is worth trying.
Of the several questions I have reviewed here on the subject of changing font colors, I assume there is no way to do this, but I will try again.
I start with a fresh copy of the MasterDetail template in xcode. The array to be loaded onto the Master view is defined as NSMutableArray *_objects;
I replace the statement that normally inserts the date/time into the row with statements to put in a sentence, "Help me display this in red as shown below:
//[_objects insertObject:[NSDate date] atIndex:0]; // removed this line and replaced with next two.
NSString *loadme = [[NSString alloc] initWithFormat:#"Help me display this in red"];
[_objects insertObject:loadme atIndex:0];
So, the question is, how would I change the display of this row on the Master view with red text? thanks for your time and expertise.
Since I think the answer to the above question is that it can't be done. Can you tell me how to put an image on the row before the text. That would be an even better solution. I suspect it has something to do with UITableViewCell, but i have no experience in this area.
There are a couple of ways that you could make this work. One, as per the comment from #CarlVeazey is to use NSAttributedString (like this) so that you can store the text and the colour together.
Another option would be to have another array where you add the colour (UIColor instances) and then when you prepare the cell you can set the label text and textColor from the two arrays.
I have a UILabel with the lineBreakMode set to UILineBreakModeWordWrap. This works fine, except when I have a long slab of text with no spaces. In this case it does not wrap the long slab of text but instead just cuts it off once it reaches the right-hand end of the UILabel frame. How can I tell the UILabel that it should wrap on a character boundary in this situation only (essentially equivalent to the UILineBreakModeCharacterWrap setting, but only for those long slabs of spaceless text).
Thanks in advance!
For anyone else having this same issue, I ended-up solving it by using a UITextView instead of a UILabel. This was the best solution for two reasons:
It doesn't require any custom behaviour to determine whether the text contains spaces and change the line break mode of the UILabel to/from word/character wrap.
More importantly, there is an edge case whereby you may have normal words (that you want to wrap on word boundaries) plus extra long text (which you need to wrap on character boundaries). Short of writing some kind of logic to insert a space into that extra long text (at the correct position) to force a "fake word wrap" I can't see any way to handle wrapping on words and characters, depending on the situation, within the one UILabel. The UITextView handles this situation automatically, breaking on word boundaries or character boundaries as necessary.
For specifics on how I am doing this, I have a one line UITextView with editing and scrolling disabled. I also set the .contentInset to remove the padding making it look (to the unsuspecting eye) just like a UILabel. I am then using the sizeWithFont:constrainedToSize:lineBreakMode: method to determine the frame of the rendered text, and adjusting the frame of the UITextView accordingly so that it exactly fits the text.
Hope that this helps!
One way to do this is to set the Lines property in IB.
or from code do this -
textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 3;
So when you set the number of lines as 3 the text wraps till that many lines are occupied.
You have to do it yourself, there's no option for 'use word wrapping except when I don't want you to' :)
If a word was too long you could insert spaces into it before you display it to help the label know where to wrap?
dean is right. If you want it you have to do it manually. The below will code will wordwrap a label even though it doesn't spaces. This may help
NSString *someText = yourLabel.text;
//Check if the text contains spaces
//The method in the below if condition is user defined and you have to define one. lol
if(![self textContainsSpaces:someText])
{
//Do the word wrap manually
CGSize constraintSize;
constraintSize.width = 165;
constraintSize.height = 165;
CGSize stringSize =[someText sizeWithFont: [UIFont boldSystemFontOfSize: 17] constrainedToSize: constraintSize lineBreakMode: UILineBreakModeWordWrap];
CGRect rect = CGRectMake(yourLabel.frame.origin.x, yourLabel.frame.origin.y, 165, (stringSize.height+10));
yourLabel.frame = rect;
}