Can I underline the text of a NSTextField from interface builder?

前端 未结 2 1165
青春惊慌失措
青春惊慌失措 2021-02-14 10:57

Can I underline the text of a NSTextField from interface builder ?

So far, I\'ve only able to change its color. Is there a way to underline it ?

thanks

2条回答
  •  醉酒成梦
    2021-02-14 11:26

    No, you'd have to do it in code. For example:

    NSMutableAttributedString *str = [[myTextField attributedStringValue] mutableCopy];
    
    [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, str.length)];
    
    [myTextField setAttributedStringValue:str];
    
    [str release];
    

提交回复
热议问题