Skip to content

Instantly share code, notes, and snippets.

@neilkennedy
Created April 29, 2013 22:03
Show Gist options
  • Save neilkennedy/5485167 to your computer and use it in GitHub Desktop.
Save neilkennedy/5485167 to your computer and use it in GitHub Desktop.
Customize MonoTouch.Dialog's "Pull to Refresh" header
using System;
using MonoTouch.Dialog;
using System.Drawing;
using MonoTouch.UIKit;
namespace lifeboxapp.monotouch
{
/// <summary>
/// Override the default MonoTouch.Dialog Pull To Refresh view so it says "Pull To Add"
/// </summary>
public class PullToAddView : RefreshTableHeaderView
{
public PullToAddView (RectangleF rect) : base (rect)
{
BackgroundColor = UIColor.FromWhiteAlpha (1, 0.4f);
StatusLabel.BackgroundColor = UIColor.Clear;
StatusLabel.TextColor = UIColor.Black;
//this doesn't make sense for "Pull to Add" so we clear the text color so it isn't seen
LastUpdateLabel.TextColor = UIColor.Clear;
LastUpdateLabel.ShadowOffset = new SizeF(0,0);
LastUpdateLabel.BackgroundColor = UIColor.Clear;
}
RefreshViewStatus status = (RefreshViewStatus) (-1);
public override void SetStatus (RefreshViewStatus status)
{
if (this.status == status)
return;
string s = "Release to Add";
switch (status){
case RefreshViewStatus.Loading:
s = "Loading...";
break;
case RefreshViewStatus.PullToReload:
s = "Pull down to Add...";
break;
}
StatusLabel.Text = s;
}
}
}
using System;
using MonoTouch.Dialog;
using MonoTouch.UIKit;
using System.Drawing;
namespace lifeboxapp.monotouch
{
/// Use this class instead of DialogViewController when implementing.
/// To make this visible in your ViewController you need to add
///
/// this.RefreshRequested += (object sender, EventArgs e) => {
/// this.ReloadComplete();
///
/// //do something here
/// };
public class PullToAddViewController : DialogViewController
{
public PullToAddViewController (UITableViewStyle style, RootElement root) : base(style, root)
{
}
/// <Docs>The boundaries for the Refresh table header view</Docs>
/// <returns></returns>
/// <summary>
/// Add our custom Pull to Add view instead of the default Pull to Refresh
/// </summary>
/// <param name="rect">Rect.</param>
public override RefreshTableHeaderView MakeRefreshTableHeaderView (RectangleF rect)
{
return new PullToAddView (rect);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment