- (void)tableView:tableView illDisplayCell:cell forTableColumn:row:row
and setting the shadow for text cells also causes a shadow on the
tableView's grid and other components.
Is there a way to only shadow text?
--
/los "I was a teenage net-random"
------------------------------------------------------------------------
Opinions expressed here are mine and not necessarily those of my employer!
------------------------------------------------------------------------
> I'd like text cells to be shown in a variety of colors, but often they
> need to be shadowed to be visible. The trouble is that using
>
> - (void)tableView:tableView illDisplayCell:cell forTableColumn:row:row
>
> and setting the shadow for text cells also causes a shadow on the
> tableView's grid and other components.
>
> Is there a way to only shadow text?
Use an NSAttributedString and set the text shadow attribute accordingly
for it.
Just about any NSCell that can display an string can display an
attributed string if you return that in your valueForRow method
Thanks but doing it that way resulted in losing column formatters and
justifications; I did try and merge whatever the column cells's
attributed string had, in the hope to augment it with shadowing but no
joy. Maybe I did this wrong (objectValueForTableColumn):
(shadow is alloc'd and init'd for the class; each 'item' has it's own
fore and back color)
[shadow setShadowColor:[item backColor]];
NSMutableAttributedString * attrStr =
[[[NSMutableAttributedString alloc]
initWithString:[NSString stringWithFormat:@"%@",
[item valueForKey:identifier]]
attributes:[NSDictionary dictionaryWithObject:shadow
forKey:NSShadowAttributeName]] autorelease];
[attrStr appendAttributedString:
[[tableColumn dataCell] attributedStringValue]];
return attrStr;
Since I lose color (negative values in red), and formatting, I just
dropped vertical and horizontal grid lines and I can live with that.
So in my willDisplayCell delegate I have this:
[cell setTextColor:[item foreColor]];
[shadow setShadowColor:[item backColor]];
[shadow setShadowOffset:NSMakeSize(2.0,-2.0)];
[shadow set];
It's also a lot faster.
On Sep 4, 8:01 pm, slashlos <slash...@optonline.net> wrote:
...
> NSMutableAttributedString * attrStr =
> [[[NSMutableAttributedString alloc]
> initWithString:[NSString stringWithFormat:@"%@",
> [item valueForKey:identifier]]
I'm not sure why this isn't
initWithString: [item valueForKey: identifier]
> attributes:[NSDictionary dictionaryWithObject:shadow
> forKey:NSShadowAttributeName]] autorelease];
And here you're in trouble. You don't own an object allocated with a
method not containing "new", "copy", or "alloc", so you must not send
it a release message. When the attributed string is dealloced, you'll
get a memory-protection error, because the shadow attribute name will
already have been released.
-- F
Fritz Anderson wrote:
> A bit off the topic of the original post, but...
> ...
> I'm not sure why this isn't
> initWithString: [item valueForKey: identifier]
It was originally, but altered in attempt to triage why numerics weren't
using their formatters; it didn't pan out and should have been restored.
>> attributes:[NSDictionary dictionaryWithObject:shadow
>> forKey:NSShadowAttributeName]] autorelease];
>
> And here you're in trouble. You don't own an object allocated with a
> method not containing "new", "copy", or "alloc", so you must not send
> it a release message. When the attributed string is dealloced, you'll
> get a memory-protection error, because the shadow attribute name will
> already have been released.
>
> -- F
Assuming I wanted to continue that path, I guess I should have also put
the string into the class along with the shadow and avoid this...?
The two are not equivalent. In particular, the original code works even if
valueForKey: returns something that's not an NSString. If it *is* an
NSString then initWithString: is redundant and you can just pass the
result of valueForKey: directly.
>> attributes:[NSDictionary dictionaryWithObject:shadow
>> forKey:NSShadowAttributeName]] autorelease];
>
> And here you're in trouble. You don't own an object allocated with a
> method not containing "new", "copy", or "alloc", so you must not send
> it a release message. When the attributed string is dealloced, you'll
> get a memory-protection error, because the shadow attribute name will
> already have been released.
You've misread the target of that message. Autorelease is going to the
NSAttributedString which he just alloc/inited, so it's perfectly
legitimate.
This is a perfect example of why it's a bad idea to put umpty-bazillion
different things into a single expression. Break that stuff into multiple
lines!
--
Michael Ash
Rogue Amoeba Software