Search code examples
delphibackgroundfiremonkeystatusbardelphi-xe8

Setting the background color of statusbar in IOS app in XE8


I want to set the background color (and foreground color) of the status bar in my freshly created Delphi XE8 Firemonkey app. With the status bar I mean the top bar with the time and wifi widgets.

I just cannot find it. I need some help :-)

Thanks, Edward


Solution

  • The Fill.Color of the form controls the color of the toolbar, and the average luminance of this color controls wether the text is white or black

    Borderstyle must be <> None, or else the toolbar will be hidden.

    If you have multiple forms, it is a bit unclear what form is used, but it seems like it is the last form being auto-created in your project file.

    Here is some relevant sourcecode from FMX.Platform.iOS.pas that documents the color of the text:

    procedure TPlatformCocoaTouch.UpdateStatusBarColor(const AForm: TCommonCustomForm);
      ...
      AppDelegate.MainWindow.RootViewController.SetStatusBarBackgroundColor((AForm as TCustomForm).Fill.Color);
      ...
    
    procedure TFMXViewController.SetStatusBarBackgroundColor(const ABackgroundColor: TAlphaColor);
      ...
      FStatusBarLuminance := Luminance(ABackgroundColor);
      ...
    
    function TFMXViewController.preferredStatusBarStyle: UIStatusBarStyle;
    begin
      if FStatusBarLuminance < 0.5 then
        Result := UIStatusBarStyleLightContent
      else
        Result := UIStatusBarStyleDefault;
    end;
    

    PS. I have another unanswered SO question about how to make the statusbar transparent, which is native iOS 7+ behavior.