Re: Parsing a text
Re: Parsing a text
- Subject: Re: Parsing a text
- From: Greg Herlihy <email@hidden>
- Date: Tue, 21 Feb 2006 19:15:58 -0800
- Thread-topic: Parsing a text
Try changing the line:
while (index < colorRange.length){
to:
while (index < [aText length]){
colorRange.length equals [aText length] only the first time through the
loop; afterwards colorRange stores the length of the current color text run.
So either index will have to be compared with [aText length] directly or
with some dedicated variable that caches aText's length.
Greg
On 2/21/06 9:44 AM, "Andrea Salomoni" <email@hidden> wrote:
> dear list,
>
> I'm findind some problems using attributesAtIndex:effectiveRange method.
> I have a NSMutableAttributedString declared as follow:
>
> NSRange colorRange;
> colorRange.location = 0;
> colorRange.length = [aText length];
> float index = 0;
>
> while (index < colorRange.length){
> NSDictionary * attributes = [aText attributesAtIndex:index
> effectiveRange:&colorRange];
>
> NSColor *color ;
> NSColor *rgbColor ;
> float r, g, b, a ;
>
> color = [attributes valueForKey:@"NSColor"] ;
> rgbColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] ;
> if( rgbColor != nil ) {
> [rgbColor getRed:&r green:&g blue:&b alpha:&a] ;
> NSString * theWebColor = [NSString stringWithFormat: @"%X%X%X",
> (unsigned)(r*255),
> (unsigned)(g*255), (unsigned)(b*255)];
...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden