Search Results

Search found 22 results on 1 pages for 'nsattributedstring'.

Page 1/1 | 1 

  • Why No NSAttributedString on the iPhone?

    - by Jasarien
    Hey guys, Does anyone know what made Apple leave out NSAttributedString when turning AppKit into UIKit? The reason I ask is that I would really like to use it in my iPhone app, and there appears to be no replacement or alternative than doing it myself... It is possible to have mixed font attributes on a string - it's just a hell of a lot of work to to achieve something similar that was possible with a few lines of code with NSAttributedString. Also, doing all this extra drawing code myself makes my table view cells really heavy, and really hurts performance. Anyone got any ideas? Any genius's working on an opensource alternative to NSAttributedString?

    Read the article

  • Load NSAttributedString from File

    - by Wayfarer
    Is there a way to have some sort of rich text in a file, and load the file into an NSAttributedString? I looked into loading a .rtf file into an NSAttributed String: NSString *filePathFooter = [[NSBundle mainBundle] pathForResource:kFooterFileName ofType:@"rtf"]; NSError *error = nil; NSAttributedString *string = [[NSAttributedString alloc] initWithFileURL:[NSURL URLWithString:filePathFooter] options:nil documentAttributes:NULL error:&error]; But this leaves me with: Error Domain=NSCocoaErrorDomain Code=258 "The operation couldn’t be completed. (Cocoa error 258.)" Is there a way to do this?

    Read the article

  • Copy NSAttributedString to pasteboard

    - by Chris
    Brand new to Cocoa and I'm trying to figure out how to copy an NSAttributedString to the pasteboard. I've looked in the docs and not sure if I'm supposed to use a NSPasteboardItem or not. Here's what I have to copy a regular NSString: NSPasteboard *pb = [NSPasteboard generalPasteboard]; NSArray *types = [NSArray arrayWithObjects:NSStringPboardType, nil]; [pb declareTypes:types owner:self]; [pb setString:@"asdfasdf" forType:NSStringPboardType]; How do I set a NSAttributedString? Thanks

    Read the article

  • iOS equivalent to MacOS NSAttributedString initWithRTF

    - by trekme
    What is an iOS equivalent to MacOS NSAttributedString initWithRTF ? The Application Kit extends Foundation’s NSAttributedString class by adding support for RTF, RTFD, and HTML (with or without attachments), graphics attributes (including font and ruler attributes), methods for drawing attributed strings, and methods for calculating significant linguistic units. - (id)initWithRTF:(NSData *)rtfData documentAttributes:(NSDictionary **)docAttributes I need to process a short stream of RTF data in an iOS application. Thank you!

    Read the article

  • Drawing an NSAttributedString into a non-rectangular CGPath?

    - by Adrian Kosmaczewski
    I generate a rather complex NSAttributedString in my iOS 3.2 application (iPad), including formatting options of type CTParagraphStyleSetting, in particular with values for kCTParagraphStyleSpecifierMinimumLineHeight and kCTParagraphStyleSpecifierParagraphSpacing. When I try to draw this attributed string into a non-rectangular CGPath, Core Text draws it but without the line spacing defined; that is, all text appears crammed in paragraphs without line spacing. Needless to say, it does not look as pretty as if the CGPath was simply defined using a single call to CGPathAddRect()! Is there any setting I can specify (to my CTFramesetterRef or to the CTFrameRef associated to the culprit CGPath) to avoid losing all line height information? Thanks!

    Read the article

  • Saving custom attributes in NSAttributedString

    - by regulus6633
    I need to add a custom attribute to the selected text in an NSTextView. So I can do that by getting the attributed string for the selection, adding a custom attribute to it, and then replacing the selection with my new attributed string. So now I get the text view's attributed string as NSData and write it to a file. Later when I open that file and restore it to the text view my custom attributes are gone! After working out the entire scheme for my custom attribute I find that custom attributes are not saved for you. Look at the IMPORTANT note here: http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/AttributedStrings/Tasks/RTFAndAttrStrings.html So I have no idea how to save and restore my documents with this custom attribute. Any help?

    Read the article

  • How to- NSAttributedString to CGImageRef

    - by kroko
    Hello! I'm writing a QuickLook plugin. Well, everything works. Just want to try it make better ;). Thus the question. Here is a function that returns thumbnail image and that I'm using now. QLThumbnailRequestSetImageWithData( QLThumbnailRequestRef thumbnail, CFDataRef data, CFDictionaryRef properties); ); http://developer.apple.com/mac/library/documentation/UserExperience/Reference/QLThumbnailRequest_Ref/Reference/reference.html#//apple_ref/c/func/QLThumbnailRequestSetImageWithData Right now I'm creating a TIFF - encapsulated it into NSData. An example // Setting CFDataRef CGSize thumbnailMaxSize = QLThumbnailRequestGetMaximumSize(thumbnail); NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc] initWithString:@"dummy" attributes:[NSDictionary dictionaryWithObjectsAndKeys: [NSFont fontWithName:@"Monaco" size:10], NSFontAttributeName, [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.0 alpha:1.0], NSForegroundColorAttributeName, nil] ] autorelease]; NSImage *thumbnailImage = [[[NSImage alloc] initWithSize:NSMakeSize(thumbnailMaxSize.width, thumbnailMaxSize.height)] autorelease]; [thumbnailImage lockFocus]; [[NSColor whiteColor] set]; NSRectFill(NSMakeRect(0, 0, thumbnailMaxSize.width, thumbnailMaxSize.height)); [attributedString drawInRect:NSMakeRect(0, 0, thumbnailMaxSize.width, thumbnailMaxSize.height)]; [thumbnailImage unlockFocus]; (CFDataRef)[thumbnailImage TIFFRepresentation]; // This is data // Setting CFDictionaryRef (CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:@"kUTTypeTIFF", (NSString *)kCGImageSourceTypeIdentifierHint, nil ]; // this is properties However QuickLook provides another function to return thumbnail image, namely QLThumbnailRequestSetImage( QLThumbnailRequestRef thumbnail, CGImageRef image, CFDictionaryRef properties); ); http://developer.apple.com/mac/library/documentation/UserExperience/Reference/QLThumbnailRequest_Ref/Reference/reference.html#//apple_ref/c/func/QLThumbnailRequestSetImage I have a feeling that passing CGImage to the QL instead of TIFF data would help in speeding things up. However- I have never worked with CG context before. I know, the documentation is there :), but anyways- could anyone give an example how to turn that NSAttributed string into CGImageRef. An example is worth 10 times reading the documentation ;) Any help appreciated. Thanks in advance!

    Read the article

  • How to get height for NSAttributedString at a fixed width

    - by bonaldi
    I want to do some drawing of NSAttributedStrings in fixed-width boxes, but am having trouble calculating the right height they'll take up when drawn. So far, I've tried: Calling - (NSSize) size, but the results are useless (for this purpose), as they'll give whatever width the string desires. Calling - (void)drawWithRect:(NSRect)rect options:(NSStringDrawingOptions)options with a rect shaped to the width I want and NSStringDrawingUsesLineFragmentOrigin in the options, exactly as I'm using in my drawing. The results are ... difficult to understand; certainly not what I'm looking for. (As is pointed out in a number of places, including this Cocoa-Dev thread). Creating a temporary NSTextView and doing: [[tmpView textStorage] setAttributedString:aString]; [tmpView setHorizontallyResizable:NO]; [tmpView sizeToFit]; When I query the frame of tmpView, the width is still as desired, and the height is often correct ... until I get to longer strings, when it's often half the size that's required. (There doesn't seem to be a max size being hit: one frame will be 273.0 high (about 300 too short), the other will be 478.0 (only 60-ish too short)). I'd appreciate any pointers, if anyone else has managed this.

    Read the article

  • String munging in Objective-C with NSAttributedString.

    - by dreeves
    I have an NSAttributedString s and an integer i and I'd like a function that takes s and i and returns a new NSAttributedString that has a (stringified) i prepended to s. It looks like some combination of -stringWithFormat:, -initWithString:, and -insertAttributedString: would do it but I'm having trouble piecing it together without a lot of convolution and temporary variables. More generally, pointers to guides on making sense of NSAttributedString and NSMutableAttributedString would be awesome.

    Read the article

  • How do you keep text from wrapping in an NSTableView using NSAttributedString

    - by Justin
    I have an NSTableView that has 2 columns, one for an icon and the other for two lines of text. In the second column, the text column, I have some larger text that is for the name of an item. Then I have a new line and some smaller text that describes the state of the item. When the name becomes so large that it doesn't fit on one line it wraps (or when you shrink the window down so small that it causes the names to not fit on a single line). row1=============== | image |  some name   | | image |   idle               | row2================ | image |  some name really long name   | <- this gets wrapped pushing 'idle' out of the view | image |   idle               | =================== My question is, how could I keep the text from wrapping and just have the NSTableView display a horizontal scroll-bar once the name is too large to fit?

    Read the article

  • Setting the background colour/highlight colour for a given string range using Core Text

    - by Jasarien
    I have some text laid out using Core Text in my iPhone app. I'm using NSAttributedString to set certain styles within the text for given ranges. I can't seem to find an attribute for setting a background / highlight colour, though it would seem it is possible. I couldn't find an attribute name constant that sounded relevant and the documentation only lists: kCTCharacterShapeAttributeName kCTFontAttributeName kCTKernAttributeName kCTLigatureAttributeName kCTForegroundColorAttributeName kCTForegroundColorFromContextAttributeName kCTParagraphStyleAttributeName kCTStrokeWidthAttributeName kCTStrokeColorAttributeName kCTSuperscriptAttributeName kCTUnderlineColorAttributeName kCTUnderlineStyleAttributeName kCTVerticalFormsAttributeName kCTGlyphInfoAttributeName kCTRunDelegateAttributeName Craig Hockenberry, developer of Twitterrific has said publicly on Twitter that he uses Core Text to render the tweets, and Twitterrific has this background / highlight that I'm talking about when you touch a link. Any help or pointers in the right direction would be fantastic, thanks. Edit: Here's a link to the tweet Craig posted mentioning "Core text, attributed strings and a lot of hard work", and the follow up that mentioned using CTFrameSetter metrics to work out if touches intersect with links.

    Read the article

  • Multiple undo managers for a text view

    - by Rui Pacheco
    Hi, I've a text view that gets its content from an attributed string stored in a model object. I list several of these model objects in a drawer and when the user clicks on one the text view swaps its content. I now need to also swap the undo manager for the text view. I initialise an undo manager on my model object and use undoManagerForTextView to return it to the text view, but something's not quite right. Strategically placed logging statements show me that everything's working as planned: on startup a new model object is initialised correctly and a non-null undo manager is always pulled by the text view. But when it comes to actually doing undo, I just can't get the behaviour I want. I open a window, type something and press cmd+z, and undo works. I open a window, type something, select a new model on the table, type something, go back to the first model and try to undo and all I get is a beep. Something on the documentation made me raise an eyebrow, as it would mean that I can't have undo with several model objects: The default undo and redo behavior applies to text fields and text in cells as long as the field or cell is the first responder (that is, the focus of keyboard actions). Once the insertion point leaves the field or cell, prior operations cannot be undone.

    Read the article

  • How to paint background of specific range of text in NSTextView

    - by Rui Pacheco
    Hi, This is not a specific bug, its more about not knowing how to do something. I've an NSTextView and I need to paint the background of specific ranges of text when the user clicks on a specific part of the text view. I've tried this but I just get erratic behaviour in the sense that sometimes text loses the foreground color or the background doesn't span the whole range: NSLayoutManager *layoutManager = [myTextView layoutManager]; [layoutManager removeTemporaryAttribute:NSBackgroundColorAttributeName forCharacterRange:range]; [[myTextView layoutManager] setTemporaryAttributes:attributes forCharacterRange:range]; For the sake of simplicity assume that range is always a valid string (it is in my testing environment).

    Read the article

  • NSTextField (Label) Attributed Text: Select

    - by huntaub
    I have a NSTextField Label that has attributed text in it. The color and size are different from the defaults. (The text is a bit larger and green) Now, I need to be able to select the text in the label so as the click the hyperlinks embedded in the attributed text. This works fine; however, when selecting the text the format of the text reverts back to the defaults (a smaller, black font). Is there anyway to stop this behavior so that my styling is preserved when the user clicks (selects text) on a Label?

    Read the article

  • Trying to create link with NSTextField

    - by Chris
    I'm using this category (is that right?) http://www.nightproductions.net/references/dsclickableurltextfield_reference.html#setAttributedStringValue to implement clickable textfields. I've imported the header file in my controller class and set it's attributed string value like this NSAttributedString* str = [[NSAttributedString alloc] initWithString:@"http://www.yahoo.com"]; [url setAttributedStringValue:(NSAttributedString *)str]; [str release]; The text field is not selectable and not editable. The text field value is set but it's not clickable and it's not a link. Thanks in advance.

    Read the article

  • [Cocoa] Binding CoreData Managed Object to NSTextFieldCell subclass

    - by ndg
    I have an NSTableView which has its first column set to contain a custom NSTextFieldCell. My custom NSTextFieldCell needs to allow the user to edit a "desc" property within my Managed Object but to also display an "info" string that it contains (which is not editable). To achieve this, I followed this tutorial. In a nutshell, the tutorial suggests editing your Managed Objects generated subclass to create and pass a dictionary of its contents to your NSTableColumn via bindings. This works well for read-only NSCell implementations, but I'm looking to subclass NSTextFieldCell to allow the user to edit the "desc" property of my Managed Object. To do this, I followed one of the articles comments, which suggests subclassing NSFormatter to explicitly state which Managed Object property you would like the NSTextFieldCell to edit. Here's the suggested implementation: @implementation TRTableDescFormatter - (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error { if (anObject != nil){ *anObject = [NSDictionary dictionaryWithObject:string forKey:@"desc"]; return YES; } return NO; } - (NSString *)stringForObjectValue:(id)anObject { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; return [anObject valueForKey:@"desc"]; } - (NSAttributedString*)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attrs { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; NSAttributedString *anAttributedString = [[NSAttributedString alloc] initWithString: [anObject valueForKey:@"desc"]]; return anAttributedString; } @end I assign the NSFormatter subclass to my cell in my NSTextFieldCell subclass, like so: - (void)awakeFromNib { TRTableDescFormatter *formatter = [[[TRTableDescFormatter alloc] init] autorelease]; [self setFormatter:formatter]; } This seems to work, but is extremely patch. On occasion, clicking to edit a row will cause its value to nullify. On other occasions, the value you enter on one row will populate other rows within the table. I've been doing a lot of reading on this subject and would really like to get to the bottom of this. What's more frustrating is that my NSTextFieldCell is rendering exactly how I would like it to. This editing issue is my last obstacle! If anyone can help, that would be greatly appreciated.

    Read the article

  • Core Text's CTFramesetterSuggestFrameSizeWithConstraints() returns incorrect size everytime

    - by nsapplication
    According to the docs, CTFramesetterSuggestFrameSizeWithConstraints () "determines the frame size needed for a string range". Unfortunately the size returned by this function is never accurate. Here is what I am doing: NSAttributedString *string = [[[NSAttributedString alloc] initWithString:@"lorem ipsum" attributes:nil] autorelease]; CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef) string); CGSize textSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(rect.size.width, CGFLOAT_MAX), NULL); The returned size always has the correct width calculated, however the height is always slightly shorter than what is expected. Is this the correct way to use this method? Is there any other way to layout Core Text? Seems I am not the only one to run into problems with this method. See https://devforums.apple.com/message/181450.

    Read the article

  • Binding CoreData Managed Object to NSTextFieldCell subclass

    - by ndg
    I have an NSTableView which has its first column set to contain a custom NSTextFieldCell. My custom NSTextFieldCell needs to allow the user to edit a "desc" property within my Managed Object but to also display an "info" string that it contains (which is not editable). To achieve this, I followed this tutorial. In a nutshell, the tutorial suggests editing your Managed Objects generated subclass to create and pass a dictionary of its contents to your NSTableColumn via bindings. This works well for read-only NSCell implementations, but I'm looking to subclass NSTextFieldCell to allow the user to edit the "desc" property of my Managed Object. To do this, I followed one of the articles comments, which suggests subclassing NSFormatter to explicitly state which Managed Object property you would like the NSTextFieldCell to edit. Here's the suggested implementation: @implementation TRTableDescFormatter - (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error { if (anObject != nil){ *anObject = [NSDictionary dictionaryWithObject:string forKey:@"desc"]; return YES; } return NO; } - (NSString *)stringForObjectValue:(id)anObject { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; return [anObject valueForKey:@"desc"]; } - (NSAttributedString*)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attrs { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; NSAttributedString *anAttributedString = [[NSAttributedString alloc] initWithString: [anObject valueForKey:@"desc"]]; return anAttributedString; } @end I assign the NSFormatter subclass to my cell in my NSTextFieldCell subclass, like so: - (void)awakeFromNib { TRTableDescFormatter *formatter = [[[TRTableDescFormatter alloc] init] autorelease]; [self setFormatter:formatter]; } This seems to work, but falls down when editing multiple rows. The behaviour I'm seeing is that editing a row will work as expected until you try to edit another row. Upon editing another row, all previously edited rows will have their "desc" value set to the value of the currently selected row. I've been doing a lot of reading on this subject and would really like to get to the bottom of this. What's more frustrating is that my NSTextFieldCell is rendering exactly how I would like it to. This editing issue is my last obstacle! If anyone can help, that would be greatly appreciated.

    Read the article

  • Create hyperlink to some text in NSTextView

    - by regulus6633
    I can create a hyperlink to some url in an NSTextView using the "Link Panel". Or I can add a link manually using the NSLinkAttributeName attribute of NSAttributedString. I don't want to make a hyperlink to some external url though, I want to be able to create a hyperlink to some text within the NSTextView. Do you know how in Pages you can set some text as a Bookmark, and then you can make a hyperlink to that bookmark? Any ideas or examples of how to go about that?

    Read the article

  • NSData-AES Class Encryption/Decryption in Cocoa

    - by David Schiefer
    hi, I am attempting to encrypt/decrypt a plain text file in my text editor. encrypting seems to work fine, but the decrypting does not work, the text comes up encrypted. I am certain i've decrypted the text using the word i encrypted it with - could someone look through the snippet below and help me out? Thanks :) Encrypting: NSAlert *alert = [NSAlert alertWithMessageText:@"Encryption" defaultButton:@"Set" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@"Please enter a password to encrypt your file with:"]; [alert setIcon:[NSImage imageNamed:@"License.png"]]; NSSecureTextField *input = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)]; [alert setAccessoryView:input]; NSInteger button = [alert runModal]; if (button == NSAlertDefaultReturn) { [[NSUserDefaults standardUserDefaults] setObject:[input stringValue] forKey:@"password"]; NSData *data; [self setString:[textView textStorage]]; NSMutableDictionary *dict = [NSDictionary dictionaryWithObject:NSPlainTextDocumentType forKey:NSDocumentTypeDocumentAttribute]; [textView breakUndoCoalescing]; data = [[self string] dataFromRange:NSMakeRange(0, [[self string] length]) documentAttributes:dict error:outError]; NSData*encrypt = [data AESEncryptWithPassphrase:[input stringValue]]; [encrypt writeToFile:[absoluteURL path] atomically:YES]; Decrypting: NSAlert *alert = [NSAlert alertWithMessageText:@"Decryption" defaultButton:@"Open" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@"This file has been protected with a password.To view its contents,enter the password below:"]; [alert setIcon:[NSImage imageNamed:@"License.png"]]; NSSecureTextField *input = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)]; [alert setAccessoryView:input]; NSInteger button = [alert runModal]; if (button == NSAlertDefaultReturn) { NSLog(@"Entered Password - attempting to decrypt."); NSMutableDictionary *dict = [NSDictionary dictionaryWithObject:NSPlainTextDocumentType forKey:NSDocumentTypeDocumentOption]; NSData*decrypted = [[NSData dataWithContentsOfFile:[self fileName]] AESDecryptWithPassphrase:[input stringValue]]; mString = [[NSAttributedString alloc] initWithData:decrypted options:dict documentAttributes:NULL error:outError];

    Read the article

  • NSLinguisticTagger on the contents of an NSTextStorage- crashing bug

    - by Remy Porter
    I'm trying to use an NSLinguisticTagger to monitor the contents of an NSTextStorage and provide some contextual information based on what the user types. To that end, I have an OverlayManager object, which wires up this relationship: -(void) setView:(NSTextView*) view { _view = view; _layout = view.layoutManager; _storage = view.layoutManager.textStorage; //get the TextStorage from the view [_tagger setString:_storage.string]; //pull the string out, this grabs the mutable version [self registerForNotificationsOn:self->_storage]; //subscribe to the willProcessEditing notification } When an edit occurs, I make sure to trap it and notify the tagger (and yes, I know I'm being annoyingly inconsistent with member access, I'm rusty on Obj-C, I'll fix it later): - (void) textStorageWillProcessEditing:(NSNotification*) notification{ if ([self->_storage editedMask] & NSTextStorageEditedCharacters) { NSRange editedRange = [self->_storage editedRange]; NSUInteger delta = [self->_storage changeInLength]; [_tagger stringEditedInRange:editedRange changeInLength:delta]; //should notify the tagger of the changes [self highlightEdits:self]; } } The highlightEdits message delegates the job out to a pool of "Overlay" objects. Each contains a block of code similar to this: [tagger enumerateTagsInRange:range scheme:NSLinguisticTagSchemeLexicalClass options:0 usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) { if (tag == PartOfSpeech) { [self applyHighlightToRange:tokenRange onStorage:storage]; } }]; And that's where the problem is- the enumerateTagsInRange method crashes out with a message: 2014-06-04 10:07:19.692 WritersEditor[40191:303] NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds This problem doesn't occur if I don't link to the mutable copy of the underlying string and instead do a [[_storage string] copy], but obviously I don't want to copy the entire backing store every time I want to do tagging. This all should be happening in the main run loop, so I don't think this is a threading issue. The NSRange I'm enumerating tags on exists both in the NSTextStorage and in the NSLinguisticTagger's view of the string. It's not even the fact that the applyHighlightToRange call adds attributes to the string, because it crashes before even reaching that line. I attempted to build a test case around the problem, but can't replicate it in those situations: - (void) testEdit { NSAttributedString* str = [[NSMutableAttributedString alloc] initWithString:@"Quickly, this is a test."]; text = [[NSTextStorage alloc] initWithAttributedString:str]; NSArray* schemes = [NSLinguisticTagger availableTagSchemesForLanguage:@"en"]; tagger = [[NSLinguisticTagger alloc] initWithTagSchemes:schemes options:0]; [tagger setString:[text string]]; [text beginEditing]; [[text mutableString] appendString:@"T"]; NSRange edited = [text editedRange]; NSUInteger length = [text changeInLength]; [text endEditing]; [tagger stringEditedInRange:edited changeInLength:length]; [tagger enumerateTagsInRange:edited scheme:NSLinguisticTagSchemeLexicalClass options:0 usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) { //doesn't matter, this should crash }]; } That code doesn't crash.

    Read the article

1