iOS: how to add a title to a date picker dialog

  

I would like to add a title to a Date Picker Dialog. This is how I create the date picker dialog :

// We should Create instance of UIDatePicker before creating main container.
// Because We use UIViewPicker for determinate finally size of picker container
// (Toolbar + Picker)
FUIDatePicker := TUIDatePicker.Create;
FUIDatePicker.setTimeZone(TNSTimeZone.Wrap(TNSTimeZone.OCClass.timeZoneForSecondsFromGMT(0)));
FUIDatePicker.setDatePickerMode(UIDatePickerModeDate);

{ Subscribing to change orientation events }
DefaultNotificationCenter.addObserver(GetObjectID, sel_getUid(‘DeviceOrientationChanged’), StringToID(FMXViewControllerFrameChanged), nil);

{ Creating Root view container for picker }
FUIOverlayView := TUIView.Create;
aUIColor := AlphaColorToUIColor($32000000);
FUIOverlayView.setBackgroundColor(aUIColor);
FUIOverlayView.setAutoresizingMask(UIViewAutoresizingFlexibleWidth or
UIViewAutoresizingFlexibleHeight or
UIViewAutoresizingFlexibleLeftMargin or
UIViewAutoresizingFlexibleRightMargin or
UIViewAutoresizingFlexibleTopMargin or
UIViewAutoresizingFlexibleBottomMargin);
FUIOverlayView.setFrame(CGRect.Create(0, 0, screen.Size.Width, screen.Size.Height));
aSingleTapGestureRecognizer := TUITapGestureRecognizer.Wrap(TUITapGestureRecognizer.Alloc.initWithTarget(GetObjectID, sel_getUid(‘HandleTap’)));
aSingleTapGestureRecognizer.setDelegate(GetObjectID);
aSingleTapGestureRecognizer.setNumberOfTapsRequired(1);
try
FUIOverlayView.addGestureRecognizer(aSingleTapGestureRecognizer);
finally
aSingleTapGestureRecognizer.release;
end;

{ Creating Root view container for picker }
FUIContainerView := TUIView.Create;
FUIContainerView.setBackgroundColor(TUIColor.Wrap(TUIColor.OCClass.whiteColor));
FUIContainerView.setAutoresizingMask(UIViewAutoresizingFlexibleWidth or
UIViewAutoresizingFlexibleLeftMargin or
UIViewAutoresizingFlexibleRightMargin);
FUIContainerView.setFrame(GetPopupFrame);
FUIContainerView.layer.setMasksToBounds(true);
FUIContainerView.layer.setCornerRadius(12);

{ Creating Toolbar }
FUIToolBar := TUIToolbar.Create;
FUIToolBar.setAlpha(0.8);
FUIContainerView.addSubview(FUIToolBar);
CreateToolbarConstraint;

{ Creating Toolbar buttons }
aButtons := TNSMutableArray.Create;
try

{ Adding Flexible Separator }
FUIFlexibleSepararator1 := TUIBarButtonItem.Create;
FUIFlexibleSepararator1.initWithBarButtonSystemItem(UIBarButtonSystemItemFixedSpace, nil, nil);
FUIFlexibleSepararator1.setWidth(5);
aButtons.addObject(NSObjectToID(FUIFlexibleSepararator1));

{ Adding clear Button }
if aBtnClearCaption <> ” then begin
FUIClearButton := TUIBarButtonItem.Create;
FUIClearButton.setTitle(StrToNSStr(aBtnClearCaption));
FUIClearButton.setStyle(UIBarButtonItemStyleBordered);
FUIClearButton.setTarget(Self.GetObjectID);
FUIClearButton.setAction(sel_getUid(‘Clear’));
aButtons.addObject(NSObjectToID(FUIClearButton));
end
else FUIClearButton := nil;

{ Adding Flexible Separator }
FUIFlexibleSepararator2 := TUIBarButtonItem.Create;
FUIFlexibleSepararator2.initWithBarButtonSystemItem(UIBarButtonSystemItemFlexibleSpace, nil, nil);
aButtons.addObject(NSObjectToID(FUIFlexibleSepararator2));

{ Adding Close Button }
if aBtnCancelCaption <> ” then begin
FUICancelButton := TUIBarButtonItem.Create;
FUICancelButton.setTitle(StrToNSStr(aBtnCancelCaption));
FUICancelButton.setStyle(UIBarButtonItemStyleBordered);
FUICancelButton.setTarget(Self.GetObjectID);
FUICancelButton.setAction(sel_getUid(‘Cancel’));
aButtons.addObject(NSObjectToID(FUICancelButton));
end
else FUICancelButton := nil;

{ Adding Flexible Separator }
FUIFlexibleSepararator3 := TUIBarButtonItem.Create;
FUIFlexibleSepararator3.initWithBarButtonSystemItem(UIBarButtonSystemItemFixedSpace, nil, nil);
FUIFlexibleSepararator3.setWidth(28);
aButtons.addObject(NSObjectToID(FUIFlexibleSepararator3));

{ Adding Done Button }
FUIDoneButton := TUIBarButtonItem.Create;
FUIDoneButton.setTitle(StrToNSStr(aBtnOKCaption));
FUIDoneButton.setStyle(UIBarButtonItemStyleDone);
FUIDoneButton.setTarget(Self.GetObjectID);
FUIDoneButton.setAction(sel_getUid(‘Done’));
aButtons.addObject(NSObjectToID(FUIDoneButton));

{ Adding Flexible Separator }
FUIFlexibleSepararator4 := TUIBarButtonItem.Create;
FUIFlexibleSepararator4.initWithBarButtonSystemItem(UIBarButtonSystemItemFixedSpace, nil, nil);
if aBtnClearCaption <> ” then FUIFlexibleSepararator4.setWidth(5)
else FUIFlexibleSepararator4.setWidth(15);
aButtons.addObject(NSObjectToID(FUIFlexibleSepararator4));

{ Adding button to Toolbar }
FUIToolBar.setItems(aButtons);

finally
aButtons.release;
end;

{ Adding DatePicker }
FUIContainerView.addSubview(FUIDatePicker);
CreateCalendarConstraint;
FUIOverlayView.addSubview(FUIContainerView);

and

{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure CreateToolbarConstraint;
var Constraint: NSLayoutConstraint;
begin
FUIToolBar.setTranslatesAutoresizingMaskIntoConstraints(False);
Constraint := TNSLayoutConstraint.Wrap(TNSLayoutConstraint.OCClass.constraintWithItem(NSObjectToID(FUIToolBar), NSLayoutAttributeLeft, NSLayoutRelationEqual, NSObjectToID(FUIContainerView), NSLayoutAttributeLeft, 1, 0));
Constraint.setActive(True);
Constraint := TNSLayoutConstraint.Wrap(TNSLayoutConstraint.OCClass.constraintWithItem(NSObjectToID(FUIToolBar), NSLayoutAttributeRight, NSLayoutRelationEqual, NSObjectToID(FUIContainerView), NSLayoutAttributeRight, 1, 0));
Constraint.setActive(True);
Constraint := TNSLayoutConstraint.Wrap(TNSLayoutConstraint.OCClass.constraintWithItem(NSObjectToID(FUIToolBar), NSLayoutAttributeBottom, NSLayoutRelationEqual, NSObjectToID(FUIContainerView), NSLayoutAttributeBottom, 1, 0));
Constraint.setActive(True);
Constraint := TNSLayoutConstraint.Wrap(TNSLayoutConstraint.OCClass.constraintWithItem(NSObjectToID(FUIToolBar), NSLayoutAttributeHeight, NSLayoutRelationEqual, nil, NSLayoutAttributeNotAnAttribute, 1, _ToolBarHeight));
Constraint.setActive(True);
end;

{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure CreateCalendarConstraint;
var Constraint: NSLayoutConstraint;
begin
FUIDatePicker.setTranslatesAutoresizingMaskIntoConstraints(False);
Constraint := TNSLayoutConstraint.Wrap(TNSLayoutConstraint.OCClass.constraintWithItem(NSObjectToID(FUIDatePicker), NSLayoutAttributeLeft, NSLayoutRelationEqual, NSObjectToID(FUIContainerView), NSLayoutAttributeLeft, 1, 0));
Constraint.setActive(True);
Constraint := TNSLayoutConstraint.Wrap(TNSLayoutConstraint.OCClass.constraintWithItem(NSObjectToID(FUIDatePicker), NSLayoutAttributeRight, NSLayoutRelationEqual, NSObjectToID(FUIContainerView), NSLayoutAttributeRight, 1, 0));
Constraint.setActive(True);
Constraint := TNSLayoutConstraint.Wrap(TNSLayoutConstraint.OCClass.constraintWithItem(NSObjectToID(FUIDatePicker), NSLayoutAttributebottom, NSLayoutRelationEqual, NSObjectToID(FUIToolBar), NSLayoutAttributetop, 1, 0));
Constraint.setActive(True);
Constraint := TNSLayoutConstraint.Wrap(TNSLayoutConstraint.OCClass.constraintWithItem(NSObjectToID(FUIDatePicker), NSLayoutAttributeHeight, NSLayoutRelationEqual, nil, NSLayoutAttributeNotAnAttribute, 1, _DefaultPickerHeight));
Constraint.setActive(True);
end;

Any idea what i need to change in this code in order to add a title ?

Comments are closed.