I am using an NSTextView to display the contents of a Credits.html file. The credits file contains URLs which I am specifying as HTML links. For example, one line in my Credits.html file may be:

"Distributed under a <a href="http://creativecommons.org/licenses/by/3.0/ " target="_blank">Creative Commons License</a>"

My problem is that the hyperlinks are always colored blue which doesn't work against the dark-colored background I am using.

In order to display the contents of the file I am using the following code:

[[textAcknowledgements textStorage] setAttributedString: [self acknowledgementString]];

which calls:

- (NSAttributedString *) acknowledgementString
{
    // get the contents of Credits.html
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"credits" ofType:@"html"]; NSMutableString * stringFileContents = [NSMutableString stringWithContentsOfFile:filePath];

NSFont * fontSystem = [NSFont systemFontOfSize:[NSFont systemFontSize]]; NSString * fontName = [NSString stringWithString:[fontSystem displayName]]; NSString * fontSize = [NSString stringWithFormat:@"%gpt",[NSFont labelFontSize]-2];

[stringFileContents replaceOccurrencesOfString:@"[ff]" withString:fontName options:NSLiteralSearch range:NSMakeRange(0, [stringFileContents length])]; [stringFileContents replaceOccurrencesOfString:@"[fs]" withString:fontSize options:NSLiteralSearch range:NSMakeRange(0, [stringFileContents length])]; NSData *myData = [stringFileContents dataUsingEncoding:NSUTF32StringEncoding];

    if (myData) {
NSMutableAttributedString * stringCredits = [[[NSMutableAttributedString alloc] initWithHTML:myData documentAttributes:nil] autorelease];
        NSRange range = NSMakeRange(0, [stringCredits length]);
[stringCredits addAttribute:NSForegroundColorAttributeName value:[NSColor greenColor] range:range];
        return stringCredits;
    } else {
        return nil;
    }
}

[The whole fonts bit is to ensure that the text is displayed using the standard system font at the standard size. I'm not sure if this is totally necessary or whether I could just hard-code the values but it seems more future-proof this way.]

All of my attempts to change the foreground color via NSForegroundColorAttributeName have failed so far as have attempts to set the color in the Credits.html file (CSS works for standard text, not links however).

Does anyone have any idea how I can solve this?

Simon
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to