2012-02-10 28 views
9

我可以從界面構建器中強調NSTextField的文本嗎?我可以從界面構建器中強調NSTextField的文本嗎?

到目前爲止,我只能改變它的顏色。有沒有辦法強調它?

謝謝

+0

檢查了這一點: [鏈接] [1] [1]:http://stackoverflow.c om/questions/6487290/iphone-uitextfield-with-rich-text – 2012-02-10 17:38:31

回答

14

不,你必須在代碼中做到這一點。例如:

NSMutableAttributedString *str = [[myTextField attributedStringValue] mutableCopy]; 

[str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, str.length)]; 

[myTextField setAttributedStringValue:str]; 

[str release]; 
+0

這是一個很大的幫助,雖然我遇到了一個錯誤,直到我將該值更改爲:NSUnderlineStyleSingle – DenVog 2012-08-11 01:20:53

+1

NSMutableAttributedString * strs = [[NSMutableAttributedString alloc] initWithAttributedString:[btnPreviousTitle attributedTitle]]; NSRange range = NSMakeRange(0,[strs length]); [strs addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSSingleUnderlineStyle] range:range]; [btnPreviousTitle setAttributedTitle:strs];幫助我使用下劃線文本製作NSButton。 – 2013-10-29 07:08:14

32

僅適用於iOS的

是,設置屬性文本,然後選擇文本,單擊鼠標右鍵>字體>下劃線

enter image description here

+0

你確定屏幕截圖帶有NSTextField嗎?我沒有看到這樣的選項來設置標題的歸屬,它看起來像是一個按鈕,而不是一個按鈕。 – Will 2015-04-07 14:01:57

+0

它應該這樣做,每個屬性字符串字段 – DeFrenZ 2015-04-07 14:51:37

+0

我沒有看到一個選項來設置要歸因的字符串。你確定你在OS X應用程序嗎?選擇NSTextField時,在Xcode裏面我看到以下內容:http://i.imgur.com/yTip3sq.png – Will 2015-04-07 15:02:48

相關問題