2012-11-20 4 views
2

는,이처럼 보이는 창문이인터페이스 빌더에서 창 제목 표시 줄에 사용자 정의 단추를 추가하려면 어떻게합니까? 나는 오른쪽에 단추를 추가 할 <p><img src="https://i.stack.imgur.com/g8Xln.png" alt="enter image description here"></p> <p></p>는이를 위해 : 인터페이스 빌더를 사용하여 내 OS X 용 응용 프로그램에서

enter image description here

가능하다면 어떻게 할 수 있습니까? 오른쪽에 "OK"버튼을 생성,

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. 
+0

경계선없는 창을 사용하고 대체 제목 표시 줄을 직접 그릴 필요가 있다고 생각합니다. –

답변

6

그러나 당신이 작은 코딩의 비트와 함께 끝낼 수, 인터페이스 빌더와 함께 할 수 없습니다 제목 표시 줄의 :

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])) 

자동 레이아웃에서는 버튼의 프레임을 하드 코딩 할 필요가 없습니다. 그리고 창의 크기를 조정하더라도 항상 제목 표시 줄의 오른쪽에 있습니다.

0

스위프트 2.2 자동 레이아웃 :