NSTextFieldにカーソルを合わせて下線を引こうとしています。私の最初の試みで起こったことは、テキストに下線が引かれていたのですが、それは前のテキストの上にありました。別の試みで、それはますます大胆になります。
-(void)mouseEntered:(NSEvent *)theEvent {
if (is_underlined)
return;
is_underlined = YES;
//NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:NSUnderlineStyleSingle] forKey:NSUnderlineStyleAttributeName];
//NSMutableAttributedString * as = [[NSMutableAttributedString alloc] initWithString:self.event.label
// attributes:attrsDictionary];
//[as autorelease];
NSMutableAttributedString * as = [[[self attributedStringValue] mutableCopy] autorelease];
[as beginEditing];
[as addAttribute:NSUnderlineStyleAttributeName
value:[NSNumber numberWithInt:NSUnderlineStyleSingle]
range:[[[self window] fieldEditor:YES forObject:self] selectedRange]];
[as endEditing];
[self setAttributedStringValue:as];
}
-(void)mouseExited:(NSEvent *)theEvent {
if (!is_underlined)
return;
is_underlined = NO;
// self.stringValue = self.event.label;
//[self setAttributedStringValue:nil];
NSMutableAttributedString * as = [[[self attributedStringValue] mutableCopy] autorelease];
[as beginEditing];
[as removeAttribute:NSUnderlineStyleAttributeName range:[[[self window] fieldEditor:YES forObject:self] selectedRange]];
// [as addAttribute:NSUnderlineStyleAttributeName
// value:[NSNumber numberWithInt:0]
// range:[[[self window] fieldEditor:YES forObject:self] selectedRange]];
[as endEditing];
[self setAttributedStringValue:as];
}