Re: Altering attributes of hyperlinked text
Re: Altering attributes of hyperlinked text
- Subject: Re: Altering attributes of hyperlinked text
- From: Sunil <email@hidden>
- Date: Fri, 2 Apr 2004 17:42:56 +0530
Hi,
What you have said is absolutely right.It seems NSTextView provides
the default color for text with attribute NSLinkAttributeName.
But you can do this, In the attributes array instead of
NSLinkAttributeName to store URL object , use some other key. This will
show the text in the color you require. but you need to write for
changing the cursor to hand , when mouse is over that text. And open
the link when mouse is clicked on that text range.
NSMutableDictionary *linkAttributes;
linkAttributes = [NSMutableDictionary dictionaryWithObject:
urlObject
forKey:
CustomLinkAttributeName];
[linkAttributes setObject: [NSColor redColor] forKey:
NSForegroundColorAttributeName];
[linkAttributes setObject: [NSNumber numberWithBool: YES]
forKey: NSUnderlineStyleAttributeName];
Begin forwarded message:
From: Jeremy Dronfield <email@hidden>
Date: 2 April 2004 4:38:01 PM GMT+05:30
To: Sunil <email@hidden>
Cc: email@hidden
Subject: Re: Altering attributes of hyperlinked text
This is what I originally tried, and I'm afraid it doesn't work.
NSLinkAttributeName takes an undefined (id) type as its value class,
containing the URL, the blue colour and underline. Using existing
methods for adding attributes to NSMutableAttributedString, it appears
to be impossible to override these appearance attributes. So what I
need to be able to do is manipulate the default values used at the
point before the link attribute is added to the text. So far I can't
see any way to do this.
-Jeremy
On 2 Apr 2004, at 11:19 am, Sunil wrote:
Is there a way to alter the default appearance attributes of
hyperlinked text in an NSTextView? The default attributes are blue
underline. I'd like to be able to colour-code different types of
hyperlink (e.g. blue for Internet URL, green for a local file and so
on). It seems to be impossible to override the default attributes at
the point when the link attribute is applied; nor can they be changed
afterwards by using the font panel.
Hi ,
I think you can change/add attributes of a text , at any time in a
TextView.
To add a link with red color at the end of the existing text , here
is the code. If you want to change the link color of existing text ,
you need to access the existing attributes and change them.
int from=[[aTextView string] length];
[editTextView insertText:urlString];
//creating array with attributes
NSMutableDictionary *linkAttributes;
linkAttributes = [NSMutableDictionary dictionaryWithObject:
urlObject
forKey:
NSLinkAttributeName];
[linkAttributes setObject: [NSColor redColor] forKey:
NSForegroundColorAttributeName];
[linkAttributes setObject: [NSNumber numberWithBool: YES]
forKey: NSUnderlineStyleAttributeName];
//adding attributes to the url string
[[editTextView textStorage] addAttributes: linkAttributes
range: NSMakeRange(from,[urlString length])];
----------------------------------------------------------------------
----
Ramesh PVK
Programmer
effigent India Pvt. Ltd.
ⅱ Home : 040 27227830
: 040 31148951
----------------------------------------------------------------------
----
In a world without walls and fences, who does still need Windows and
Gates ?
----------------------------------------------------------------------
----
Ramesh PVK
Programmer
effigent India Pvt. Ltd.
ⅱ Home : 040 27227830
: 040 31148951
----------------------------------------------------------------------
----
In a world without walls and fences, who does still need Windows and
Gates ?
------------------------------------------------------------------------
--
Ramesh PVK
Programmer
effigent India Pvt. Ltd.
ⅱ Home : 040 27227830
: 040 31148951
------------------------------------------------------------------------
--
In a world without walls and fences, who does still need Windows and
Gates ?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.