Home/Patches, Uncategorized/Making the Firemonkey TComboBox picker in iOS7 opaque

Making the Firemonkey TComboBox picker in iOS7 opaque

Views:
17

I really don’t know what possessed the people at Apple to make the UIPickerView transparent by default; it can make it very difficult to distinguish the items in the list from what is underneath.

In the FireMonkey TComboBox in Delphi XE5, the picker is implemented using the native UIPickerView. The way the picker is implemented, it makes it close to impossible to change its properties without modifying the FMX source. There is another way, however it is a way more complex hack and I won’t go into it here.

This method is far simpler, as long as your edition of Delphi includes source. To make the picker opaque, you can copy the file FMX.Pickers.iOS.pas (in the <DelphiDir>\source\FMX folder) to your project directory, and make the following change:

constructor TListBoxPopupDialog.Create;
begin
  inherited Create;
  FValues := TNSMutableArray.Create;

  // ListBox picker
  FListBoxPicker := TUIPickerView.Create;
  FListBoxPicker.setFrame(GetContentFrame);
  FListBoxPicker.setShowsSelectionIndicator(True);
  FListBoxPicker.setAutoresizingMask(UIViewAutoresizingFlexibleWidth);
  FDelegate := TPickerDelegate.Create(FValues);
  FDataSource := TPickerDataSource.Create(FValues);
  FListBoxPicker.setDataSource(FDataSource.GetObjectID);
  FListBoxPicker.setDelegate(FDelegate.GetObjectID);
  FListBoxPicker.setBackgroundColor(TUIColor.Wrap(TUIColor.OCClass.whiteColor)); // <-- ADD THIS LINE
  FUIContainerView.addSubview(FListBoxPicker);
end;

Now the combo box picker will be opaque. Note: This applies to the device only. For some reason I am yet to work out, the old style picker shows on the simulator.

By | 2017-02-16T18:02:36+00:00 October 16, 2013 9:18 am|Patches, Uncategorized|1 Comment

About the Author:

One Comment

  1. brent shelton November 15, 2013 at 11:17 pm - Reply

    I agree completely. When I saw the transparent picker I thought that is ugly.

Leave a Reply

Show Buttons
Hide Buttons