1
votes

Okay, this is driving me nuts. This is my code:

I downloaded the premium styles and placed the iOS ones in C:\Users\Public\Documents\RAD Studio\11.0\Styles\iOS

begin
  TStyleManager.SetStyleFromFile('iOSJet.style');
  TStyleManager.SetStyleFromFileHiRes('iOSJet2x.style');
  Application.Initialize;
  Application.CreateForm(TFormMain, FormMain);
  Application.Run;
end

If have added these two files to "deployment"

  • iOSJet.style
  • iOSJet2x.style

But my app still opens using the default ios6 style. When I step through code this happens:

  Result := False;
  S := LoadFromFile(FileName);
  if Assigned(S) then
  begin
    // Does NOT enter here?
    Result := True;
    SetStyle(S);
  end;

What is confusing is hat I use the code officially shown by Embarcadero:

Has anyone gotten styles working? And if so, how exactly?

1
Do you see the new style applied in the form designer?Doug Rudd
You'll need to deploy the style file to the device and then pass the full file path to SetStyleFromFile. Better to include the file as a resource and read it from the resource into the system style.Mike Sutton
@DougRudd yes - it is.Tom
@MikeSutton I thought it would be sufficient using TStyleBook. Thanks!Tom
TStyleBook only sets the style for the form on which it is placed. Also you'll need to set the StyleBook property of the form to point to it (I can't remember what happens with HiRes styles on XE4 - possibly a StyleBookHiRes property?).Mike Sutton

1 Answers

0
votes

This seems to work

procedure msSetupStyles;
var
  vAppDataDirPathRoot: string;
  vAppDataDirPathExec: string;
  vStylePath: string;
  vAppTitle: string;
  AppService: IFMXApplicationService;
begin
  vAppTitle := Application.Title;
  if vAppTitle = '' then
    begin
      if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationService, IInterface(AppService)) then
        begin
          vAppTitle := AppService.GetTitle;
        end
      ;
    end
  ;
  vAppDataDirPathRoot := TPath.GetHomePath + PathDelim;
  vAppDataDirPathExec := vAppDataDirPathRoot + vAppTitle + '.app' + PathDelim; 
  //--
  vStylePath := vAppDataDirPathExec + 'iOSJet.style';
  if FileExists(vStylePath) then
    begin
      TStyleManager.SetStyleFromFile(vStylePath);
      vStylePath := vAppDataDirPathExec + 'iOSJet2x.style';
      if FileExists(vStylePath) then
        begin
          TStyleManager.SetStyleFromFileHiRes(vStylePath);
        end
      ;
    end
  ;
end;