2

私の OS X アプリでは、Interface Builder を使用して、次のようなウィンドウが表示されます。

ここに画像の説明を入力

これを実現するために、右側にボタンを追加したいと思います。

ここに画像の説明を入力

これが可能である場合、どうすればそれを行うことができますか?

4

2 に答える 2

6

Interface Builder で行うことはできませんが、少しのコーディングで行うことができます。

NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton]; // Get the existing close button of the window. Check documentation for the other window buttons.
NSView *titleBarView = closeButton.superview; // Get the view that encloses that standard window buttons.
NSButton *myButton = …; // Create custom button to be added to the title bar.
myButton.frame = …; // Set the appropriate frame for your button. Use titleBarView.bounds to determine the bounding rect of the view that encloses the standard window buttons.
[titleBarView addSubview:myButton]; // Add the custom button to the title bar.
于 2012-11-20T15:23:43.820 に答える
0

Swift 2.2 およびAuto Layout、タイトル バーの右側に「OK」ボタンを作成します。

let myButton = NSButton()
myButton.title = "OK"
myButton.bezelStyle = .RoundedBezelStyle

let titleBarView = window!.standardWindowButton(.CloseButton)!.superview!
titleBarView.addSubview(myButton)
myButton.translatesAutoresizingMaskIntoConstraints = false
titleBarView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[myButton]-2-|", options: [], metrics: nil, views: ["myButton": myButton]))
titleBarView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-1-[myButton]-3-|", options: [], metrics: nil, views: ["myButton": myButton]))

自動レイアウトでは、ボタンのフレームをハードコードする必要はありません。また、ウィンドウのサイズを変更しても、常にタイトル バーの右側に表示されます。

于 2016-08-07T05:45:37.033 に答える