How to change the title of Timepicker and localization in custom renderer

ThaboSivaThaboSiva LKMember ✭✭

I have Xamarin forms time picker following custom renderer for IOS

    [assembly: ExportRenderer(typeof(TimePicker), typeof(Time24PickerRenderer))]
    namespace LabOraTimeStamp.iOS.Renderers
    {
        public class Time24PickerRenderer:TimePickerRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
            {
                base.OnElementChanged(e);
                var timePicker = (UIDatePicker)Control.InputView;
                timePicker.Locale = new NSLocale("no_nb");

                //Get the Done button
                var toolbar = (UIToolbar)Control.InputAccessoryView;
                var doneBtn = toolbar.Items[1];

                //Set the Done to OK
                doneBtn.Title = "OK";
            }
        }
    }

I wanted to change the default "done" to "Ok".

1) How can I do that? the line mentioned above for setting the title does not affect anything.

2) I already implemented localization for xamarin forms.I just wanted to use existing Resx values from custom renderer to show the string for appropriate culture.How can I achieve that?

Best Answer

Answers

  • ThaboSivaThaboSiva LKMember ✭✭

    @Mabrouk Thank you .It does the work.The "Title" property does nothing while the UIBarButtonItem style is applied. As per your answer we add our own "OK" style to UIBarButtonItem.

Sign In or Register to comment.