Created
June 16, 2015 02:57
-
-
Save ytabuchi/bd590564f1a81f9d8188 to your computer and use it in GitHub Desktop.
BottomBar Renderer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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