Change window title bar colour
From Free Pascal wiki
Jump to navigationJump to searchThe printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
This article applies to macOS only.
See also: Multiplatform Programming Guide
For macOS 10.10 and later, the following code may be used to change the colour of a window's title bar.
{$modeswitch objectivec2}
interface
uses
CocoaAll,
...;
const
NSWindowTitleVisible = 0;
NSWindowTitleHidden = 1;
type
NSWindowTitleVisibility = NSInteger;
NSWindowGlam = objccategory external (NSWindow)
function titleVisibility: NSWindowTitleVisibility; message 'titleVisibility';
procedure setTitleVisibility(AVisibility: NSWindowTitleVisibility); message 'setTitleVisibility:';
function titlebarAppearsTransparent: Boolean; message 'titlebarAppearsTransparent';
procedure setTitlebarAppearsTransparent(AFlag: Boolean); message 'setTitlebarAppearsTransparent:';
end;
{ TForm1 }
procedure TForm1.FormShow(Sender: TObject);
var
w :NSWindow;
begin
w := NSView(Self.Handle).window;
w.setTitlebarAppearsTransparent(true);
w.setTitleVisibility( NSWindowTitleHidden);
w.setBackgroundColor( NSColor.greenColor ); // <-- not required, and can changed to any color
...
end;