Skip to content

Instantly share code, notes, and snippets.

@nicwise
Created August 6, 2012 09:31
Show Gist options
  • Save nicwise/3272672 to your computer and use it in GitHub Desktop.
Save nicwise/3272672 to your computer and use it in GitHub Desktop.
base dialog view controller
using System;
using MonoTouch.Dialog;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using MicroAgent.Common;
using System.Drawing;
using MonoTouch.CoreFoundation;
using MonoTouch.Foundation;
namespace MicroAgent.Library
{
public class CommonBaseDialogViewController : DialogViewController
{
public Action ResetParent;
public CommonBaseDialogViewController () : this(null, false)
{
}
public CommonBaseDialogViewController(RootElement root, bool pushing) : base(root, pushing) {}
public virtual void ReloadFromDatabase()
{
}
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
TableView.BackgroundColor = UIColor.Clear;
}
}
public class BaseDialogViewController : CommonBaseDialogViewController
{
public BaseDialogViewController () : this(null, false)
{
}
public BaseDialogViewController(RootElement root, bool pushing) : base(root, pushing) {}
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
View.BackgroundColor = UIColor.FromPatternImage(Resources.Background);
//TableView.BackgroundView = new UIImageView(Resources.Background);
if (!Util.IsIOS5OrBetter)
{
if (NavigationController != null)
{
NavigationController.NavigationBar.TintColor = Resources.NavBarTintColor;
//TableView.BackgroundColor = UIColor.Clear;
}
}
}
public void SetNavBarTitle()
{
NavigationItem.Title = "Overview";
NavigationItem.TitleView = new UIImageView(Resources.NavControllerLogo);
TabBarItem.Title = "Overview";
}
public UIView MakeOverviewSectionHeader(string headerText)
{
var view = new UIView(new RectangleF(0,0,320,35)) {
BackgroundColor = UIColor.Clear
};
UILabel lab = new UILabel(new RectangleF(18, 10, 310,21));
lab.BackgroundColor = UIColor.Clear;
lab.Font = UIFont.BoldSystemFontOfSize(15f);
lab.TextColor = Resources.UISectionTitleColor;
lab.ShadowColor = UIColor.White.ColorWithAlpha(0.4f);
lab.ShadowOffset = new SizeF(0, 1);
lab.Text = headerText;
view.AddSubview(lab);
return view;
}
public static UIView MakeEmptySectionFooter()
{
UIFont font = UIFont.SystemFontOfSize(15f);
SizeF maxSize = new SizeF(280, 999);
var view = new UIView(new RectangleF(0,0,280, 2)) {
BackgroundColor = UIColor.Clear
};
return view;
}
public UIView MakeSectionFooter(string text)
{
UIFont font = UIFont.SystemFontOfSize(15f);
SizeF maxSize = new SizeF(280, 999);
SizeF size = new NSString(text).StringSize(font, maxSize, UILineBreakMode.WordWrap);
var view = new UIView(new RectangleF(0,0,size.Width, size.Height+15)) {
BackgroundColor = UIColor.Clear
};
UILabel lab = new UILabel(new RectangleF(20,10,size.Width, size.Height));
lab.BackgroundColor = UIColor.Clear;
lab.Font = font;
lab.TextColor = Resources.UISectionTitleColor;
lab.ShadowColor = UIColor.White.ColorWithAlpha(0.4f);
lab.ShadowOffset = new SizeF(0, 1);
lab.Text = text;
lab.Lines = 10;
view.AddSubview(lab);
return view;
}
}
public class WhiteBackgroundBaseDialogViewController : CommonBaseDialogViewController
{
public WhiteBackgroundBaseDialogViewController () : this(null, false)
{
}
public WhiteBackgroundBaseDialogViewController(RootElement root, bool pushing) : base(root, pushing) {}
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
View.BackgroundColor = UIColor.White;
//TableView.BackgroundView = new UIView {
// BackgroundColor = UIColor.White
//};
if (!Util.IsIOS5OrBetter)
{
if (NavigationController != null)
{
NavigationController.NavigationBar.TintColor = Resources.NavBarTintColor;
//TableView.BackgroundColor = UIColor.Clear;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment