Xamarin.Forms 24 hour TimePicker on iOS

by Runar Ovesen Hjerpbakk


I'm utilizing Xamarin.Forms in my next app to more easily support both iOS, Android and Windows Phone using the (mostly) same code base. It's relatively new however, and some use cases are not yet supported using Xamarin's supplied controls.

The Problem

My problem today was showing a TimePicker using a 24 hour time format, regardless of the users selected locale. The TimePicker normally respects the users preference, but I'm using the control to select a range of time, not a point in time.

TimePicker's Format property only affects the string showing the selected time, not the selection itself.

Forcing 24 hours on iOS

Since my next app will first be released on iOS (naturally), I tackled the problem there first. My solution was to create a custom renderer which forces the underlying UIDatePicker to always use a local with a 24 hour time format. In this case I chose Norwegian, but any 24h locale will do.

 
The picture illustrates what I wanted to accomplish.

The picture illustrates what I wanted to accomplish.

To use the code yourself, just drop the class into your iOS project and use the TimePicker normally in your shared project or PCL.


Xamarin.Forms and iOS Simulator Scrolling

by Runar Ovesen Hjerpbakk


Here are a couple of Xamarin quick tips i have found useful the last couple of days.

iOS simulator refuses to scroll

If your iOS simulator refuses to scroll your ListView or TableView, try restarting it. The simulator sometimes locks up and disables scrolling for some reason. This has only happened during my Xamarin.Forms development, but I have no clue as of the source.

Open another instance of Xamarin Studio

To open another instance of Xamarin Studio on OS X, use the following command in the Terminal.app:

open -n "/Applications/Xamarin Studio.app"

Given that Xamarin Studio is in its default location. Sometimes Unix can be useful, who knew? :)