Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iOS のステータスバーの色を変える
unit uIOSUtils;
interface
uses
System.UITypes;
procedure SetStatusBarColor(const iColor: TAlphaColor);
implementation
{$IFDEF IOS}
uses
System.Rtti
, FMX.Types
, FMX.Platform;
procedure SetStatusBarColor(const iColor: TAlphaColor);
var
RttiType: TRttiType;
RttiField: TRttiField;
RttiMethod: TRttiMethod;
Cocoa: TObject;
AppDelegate: TObject;
FMXWindow: TObject;
ViewControler: TObject;
Intf: IInterface;
begin
Intf := TPlatformServices.Current.GetPlatformService(IFMXApplicationService);
if (Intf = nil) then
Exit;
Cocoa := (Intf as TObject);
// TPlatformCocoaTouch
RttiType := SharedContext.GetType(Cocoa.ClassType);
if (RttiType = nil) then
Exit;
RttiField := RttiType.GetField('FAppDelegate');
if (RttiField = nil) then
Exit;
AppDelegate := RttiField.GetValue(Cocoa).AsObject;
if (AppDelegate = nil) then
Exit;
// TApplicationDelegate
RttiType := SharedContext.GetType(AppDelegate.ClassType);
if (RttiType = nil) then
Exit;
RttiField := RttiType.GetField('FMainWindow');
if (RttiField = nil) then
Exit;
FMXWIndow := RttiField.GetValue(AppDelegate).AsObject;
if (FMXWIndow = nil) then
Exit;
// TFMXWindow
RttiType := SharedContext.GetType(FMXWIndow.ClassType);
if (RttiType = nil) then
Exit;
RttiField := RttiType.GetField('RootViewController');
if (RttiField = nil) then
Exit;
ViewControler := RttiField.GetValue(FMXWIndow).AsObject;
if (ViewControler = nil) then
Exit;
// TFMXViewController
RttiType := SharedContext.GetType(ViewControler.ClassType);
if (RttiType = nil) then
Exit;
RttiMethod := RttiType.GetMethod('SetStatusBarBackgroundColor');
if (RttiMethod = nil) then
Exit;
RttiMethod.Invoke(ViewControler, [iColor]);
end;
{$ELSE}
{$WARNINGS OFF}
procedure SetStatusBarColor(const iColor: TAlphaColor);
begin
end;
{$WARNINGS ON}
{$ENDIF}
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.