Skip to content

Instantly share code, notes, and snippets.

@ytabuchi
Created June 16, 2015 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytabuchi/bd590564f1a81f9d8188 to your computer and use it in GitHub Desktop.
Save ytabuchi/bd590564f1a81f9d8188 to your computer and use it in GitHub Desktop.
BottomBar Renderer
using System;
using System.Collections.Generic;
using MonoTouch.UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using CustomFormsSample.Views;
using CustomFormsSample.iOS.Views;
[assembly: ExportRenderer(typeof(BottomBar), typeof(BottomBarRenderer))]
namespace CustomFormsSample.iOS.Views
{
public class BottomBarRenderer : ViewRenderer<BottomBar, UIToolbar>
{
private UIBarButtonItem button1;
private UIBarButtonItem button2;
protected override void OnElementChanged(ElementChangedEventArgs<BottomBar> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
var toolBar = new UIToolbar()
{
BarStyle = UIBarStyle.Default,
};
this.button1 = new UIBarButtonItem("1", UIBarButtonItemStyle.Bordered, this.OnFirst)
{
AccessibilityLabel = "1",
};
this.button2 = new UIBarButtonItem("2", UIBarButtonItemStyle.Bordered, this.OnSecond)
{
AccessibilityLabel = "2",
};
var barItems = new List<UIBarButtonItem>()
{
new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
this.button1,
new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
this.button2,
new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
};
toolBar.SetItems(barItems.ToArray(), true);
this.SetNativeControl(toolBar);
this.SetNeedsDisplay();
}
}
private void OnFirst(Object sender, EventArgs e)
{
new UIAlertView("Tapped", "1 Tapped", null, "OK", null).Show();
}
private void OnSecond(Object sender, EventArgs e)
{
new UIAlertView("Tapped", "2 Tapped", null, "OK", null).Show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment