7
A
答えて
19
はviewDidLoad
どこかでこれを試してみてください。スウィフト3では
:
let pstyle = NSMutableParagraphStyle()
pstyle.alignment = .center
button.attributedTitle = NSAttributedString(string: "Title", attributes: [ NSForegroundColorAttributeName : NSColor.red, NSParagraphStyleAttributeName : pstyle ])
0
button.attributedTitle = NSMutableAttributedString(string: "Hello World", attributes: [NSAttributedStringKey.foregroundColor: NSColor.white, NSAttributedStringKey.paragraphStyle: style, NSAttributedStringKey.font: NSFont.systemFont(ofSize: 18)])
+0
Xcodeの9はまだ出ていないと、これは私はあなたがここに銃をジャンプしていると思う変更されないことがありますが、それほどのいずれかGMではありません – Chris
1
スウィフトSwift4で、それは上書きせずにのみ要求された属性を変更しますので、私は追加の答えとしてこれを追加しました
4追加のものを追加することができます。
if let mutableAttributedTitle = button.attributedTitle.mutableCopy() as? NSMutableAttributedString {
mutableAttributedTitle.addAttribute(.foregroundColor, value: NSColor.white, range: NSRange(location: 0, length: mutableAttributedTitle.length))
button.attributedTitle = mutableAttributedTitle
}
関連する問題
- 1. NSButtonのカスタムスタイルはプログラムで<OSX/Objective-C>
- 2. OSX - NSButton:チェックボックスのインセットをタイトルラベルに設定します
- 3. カーソルがあるときNSButtonのタイトルを変更する方法
- 4. NSButtonのタイトルはCALayerがXamarin.MacのNSButtonレイヤーに設定されているときは表示されません
- 5. 定義スウィフトマックで構造体のApp
- 6. ionic css footer backgrondタイトルの色と色
- 7. AlertDialogタイトルの下線の色
- 8. ggplotタイトルの位置と色
- 9. ツールバーのタイトル文字色
- 10. NSButtonからNSButtonをストーリーボードで開く
- 11. NSButton +& - ボタン
- 12. NSButtonのグラデーションスタイル
- 13. NSButtonがプッシュされると灰色に変わります
- 14. NSButtonは背景色を設定しました。macOS 10.12
- 15. swift mac osx NSButtonが長時間押すまで応答しない
- 16. NSButtonの値は1
- 17. NSButtonからのNSEvent
- 18. のUITableView変更ヘッダのタイトルの色
- 19. Xamarin.Formsコンテンツページのタイトルの色の変更
- 20. デフォルトNSRecessedBezelStyle NSButtonビジュアルバグ?
- 21. NSButtonとイメージアニメーション
- 22. NSButtonとメニュー
- 23. uibutton内のタイトルの色を調べる
- 24. xCode TabBarItemのタイトルとアイコンの色
- 25. Swift OSX NSImageViewドラッグアンドドロップ
- 26. タイトルの色を変更するRichTextBox VB.NET
- 27. スウィフト3 OSX button.addTarget
- 28. ラジオボタンのグループとしてのNSButtonのグループ
- 29. コントローラビューのチェックボックス(NSButton)へのアクセス
- 30. ポップオーバーとNSButtonプログラム的
あなたは私の一日行わおかげで男! 'てみましょうparagraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = .center button.attributedTitle = NSAttributedString(文字列:あなたは' .Center' – PhiceDev
"タイトル"、属性:[NSForegroundColorAttributeName:NSColor.red、NSParagraphStyleAttributeName:paragraphStyle]) ' – Sebastian
スウィフト3バージョンに '.CenterTextAlignment'を変更する必要がありスウィフト2では –