I'm trying to change the color of a button's text by setting it's title using 
an attributed string; there are code snippets on the web, but I'm seeing a crash


NSAttributedString *attrTitle;
NSDictionary *dict;

dict = [NSDictionary dictionaryWithObjectsAndKeys:
        colr, NSForegroundColorAttributeName,
        nil];
attrTitle = [[NSAttributedString alloc] initWithString:titl attributes:dict];

NSLog(@"Title [EMAIL PROTECTED]", [attrTitle string]);
NSLog(@"Color [EMAIL PROTECTED]", [colr description]);

[bp setAttributedTitle:attrTitle];

Crash is in this last line, in realizeClass within _objc_fixupMesageRef
The NSLog calls produce the proper results with no fuss.

I've seen the same crash with several flavors of code.

    NSMutableAttributedString *attrTitle;
    int len;
    NSRange rng;

    len = [titl length];
    rng = NSMakeRange(0, len);

    attrTitle = [[NSMutableAttributedString alloc] initWithString:titl];
    [attrTitle beginEditing];
    [attrTitle addAttribute:NSForegroundColorAttributeName value:colr 
range:rng];
    [attrTitle endEditing];

Crash is within endEditing
Initial version based on web source:

    NSMutableAttributedString *attrTitle;
    int len;
    NSRange rng;

    len = [titl length];
    rng = NSMakeRange(0, len);

    attrTitle = [[NSMutableAttributedString alloc] initWithString:titl];
    [attrTitle addAttribute:NSForegroundColorAttributeName value:colr 
range:rng];
    [attrTitle fixAttributesInRange:rng];

Crash is in fixAttributesInRange

So the problem is occuring in the Attributed String stuff itself, not in the 
button.

This kind of stuff drives me nuts!  I'll try recompiling in 32-bit later for 
comparison.



      
_______________________________________________

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