It’s kind of obvious in retrospect about enabling or disabling animation. It’s part of some code where I’ve added a UIImage onto a MkMapView (Apple’s iOS Controls for displaying a map), that centres the map on your current location when you click it. The button is a gun sight type icon and I’ve located in the bottom right edge of the map.

    private UIButton btnCurrentLoc; // defined at the class level

// in ViewDidLoad
    var ImageCurrentLoc = UIImage.FromBundle("images/currentloc.png");
    ImageCurrentLoc.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);

    btnCurrentLoc = new UIButton() { TintColor = UIColor.Black };
    btnCurrentLoc.SetImage(ImageCurrentLoc, UIControlState.Normal);
    btnCurrentLoc.Frame = new RectangleF(View.Frame.Width-50, View.Frame.Height - 100, ImageCurrentLoc.Size.Width, ImageCurrentLoc.Size.Height);

    btnCurrentLoc.TouchUpInside += (s, e) =>
                {
                    map.SetCenterCoordinate(map.UserLocation.Location.Coordinate,true);  // animated
                    //map.CenterCoordinate = map.UserLocation.Location.Coordinate;       // not animated, moves directly            
                }; 

  View.AddSubview(map);            // has to be this way round! map first then control
  View.AddSubview(btnCurrentLoc);

Note that you add the map first to the view then the button.

As it’s commented if you click the btnCurrentLoc button, it will animate the map so you can see it scroll to your location. If you comment out that line and uncomment the line below, when you click the button it will move there immediately.

iPhone MkMapView with home button

I wanted a RadioButton type of effect with three icons. Click one of the other three and it is set to blue and the other two are coloured red. It’s actually very easy once you know the trick. You have to tell iOS 8 that the each icon image is rendered AlwaysOriginal. UIImageRenderingMode is an enum with three values (AlwaysOriginal, AlwaysTemplate and Automatic).

To display the Icon in a colour, set the RenderingMode to AlwaysOriginal then create a UIButton from it and set the TintColor to whatever you want it to be. Image1 etc are declared at the class level as UIImage, btnOne etc is a UIButton and tbar is a UIToolbar.

  tbar = new UIToolbar(new RectangleF(0, 30, 320, 44)); // hard coded values for toolbar size/location
  View.AddSubview(tbar);

  var Image1 =UIImage.FromBundle("images/image1.png");
  Image1.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
  btnOne = new UIBarButtonItem { Image = Image1, Title = "First Button", TintColor = UIColor.Blue };

// Repeat for button2, 3 etc
//  Add a click handler to each button
   btnOne.Clicked += (s, e) =>
            {
                ClearTints(); // three line method sets all buttons to red
                btnOne.TintColor = UIColor.Blue;
            };
tbar.SetItems(new []{btnOne,btnTwo,btnThree},false );

This shows three icons before and after the second one is selected.

Three icons before and after selection

iOS 8 Deprecated quite a few things- for instance if you did a map search using the Xamarin MapDemo, it uses a UISearchDisplayController but that’s now deprecated and you are meant to start using UISearchController instead.

Knowing which version of iOS your App is running on then becomes important. While I can use the older UISearchDisplayController on iOS 8, I can’t use the newer UISearchController on iOS 7.

Now I’ve been previously using this property to check if the OS is a certain version.

        public bool IsiOS8
        {
            get { return UIDevice.CurrentDevice.CheckSystemVersion(8, 0); }
        }

But I think it’s better to check if a version is >= 7 and for that purposes the MonoTouch.Foundation class provides NSProcessInfo() with it’s OperatingSystemVersion and Major and Minor properties. Note I’ve also changed IsiOS8 from a property to a function.

        public static bool IsiOS8()
{
return (new NSProcessInfo().OperatingSystemVersion.Major >= 8);
}