Dev*_*Dev 5 macos cocoa interface-builder nstextfield strikethrough
是否有可能删除标签(NSTextField)中的文本?
我试图使用字体面板,但显然当我尝试设置它们时会忽略它们:


您可以这样做,假设_textField在xib中设置为插座:
- (void) awakeFromNib
{
NSMutableAttributedString *as = [[_textField attributedStringValue] mutableCopy];
[as addAttribute:NSStrikethroughStyleAttributeName value:(NSNumber *)kCFBooleanTrue range:NSMakeRange(0, [as length])];
[_textField setAttributedStringValue:[as autorelease]];
}
Run Code Online (Sandbox Code Playgroud)
编辑:
如果您想要编写自定义删除线NSTextFieldCell子类,则唯一需要覆盖的方法是setStringValue:
- (void) setStringValue:(NSString *)aString
{
NSMutableAttributedString *as = [[NSMutableAttributedString alloc] initWithString:aString];
[as addAttribute:NSStrikethroughStyleAttributeName value:(NSNumber *)kCFBooleanTrue range:NSMakeRange(0, [as length])];
[self setAttributedStringValue:[as autorelease]];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1985 次 |
| 最近记录: |