Skip to content

Instantly share code, notes, and snippets.

@Splat
Created January 14, 2013 16:41
Show Gist options
  • Save Splat/4531390 to your computer and use it in GitHub Desktop.
Save Splat/4531390 to your computer and use it in GitHub Desktop.
using System;
using System.Drawing;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.CoreGraphics;
public class SplatClearToolbar: UIToolbar
{
UIViewController vc;
public SplatClearToolbar (UIViewController vc) : base ()
{
this.vc = vc; // hang around the reference for custom actions needed
BarStyle = UIBarStyle.Black;
//TintColor = SOMEUICOLOR; // Use to tint your buttons
// need to draw a proper clear context as image to fill the toolbar for iOS 5+
RectangleF rect = new RectangleF(0, 0, 1, 1);
UIGraphics.BeginImageContext(new SizeF(1.0f,1.0f));
CGContext context = UIGraphics.GetCurrentContext();
UIColor.Clear.SetFill();
context.FillRect(rect);
UIImage transparentImage = UIGraphics.GetImageFromCurrentImageContext();
SetBackgroundImage(transparentImage, UIToolbarPosition.Any, UIBarMetrics.Default);
context.RestoreState();
Frame = GetFrame (); // setup your frame as necessary
BindYourButtons(); // add and align your buttons to the toolbar
}
private void GetFrame()
{
throw NotImplementedException;
}
private void GetButtons()
{
throw NotImplementedException;
}
}
@Splat
Copy link
Author

Splat commented Jan 14, 2013

This Gist is how I got a clear toolbar to finally work in a subclassed UIToolbar in MonoTouch for iOS 5.0+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment