2016-07-16 1 views
0

MacOS用のNSStatusBar.systemStatusBar関連アプリケーションを作成するとき、私はまず不思議そうな問題に遭遇しました。問題は、NSStatusBarのイメージとテキストを使用するときに、ハードコードされた十分な長さを手動で指定しないと、長さが交互に問題が発生しない限り、テキストが切り捨てられていたことです。どのようにこれを解決することができますか?Cocoa/Swift:画像を使用しているときにNSStatusBarItemのテキストが切り詰められる

// The -1 is supposed to mean "variable length" 
let myStatusItem = NSStatusBar.systemStatusBar().statusItemWithLength(CGFloat(-1)) 
myStatusItem.image = NSImage(named: "customImage") 
myStatusItem.title = "Some special information" 

これは、この問題が発生する通常のケースです。 BOTH.TITLEとを使用した場合

答えて

0

いくつかのばかげたバリエーションで遊んでた後、私はこの問題は、固定することもできることに気づきました。 attributedTitle NSStatusBar項目のパラメータ。

また、.image BEFOREを宣言していることを確認してください。あなたは.attributedTitleを使用したい場合は、.TITLEた後、それを定義する - あなたは、プレーン.TITLEを使用したい場合は、単に.attributedTitle後にそれを定義します。

// The -1 is supposed to mean "variable length" 
let myStatusItem = NSStatusBar.systemStatusBar().statusItemWithLength(CGFloat(-1)) 
myStatusItem.image = NSImage(named: "customImage") 
myStatusItem.title = "Some special information" 
myStatusItem.attributedTitle = NSAttributedString(string: "Some special information") 
関連する問題