Created
January 8, 2016 12:10
-
-
Save freeonterminate/aa068f6b6698bf2e0f4e to your computer and use it in GitHub Desktop.
iOS のステータスバーの色を変える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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