Skip to content

Instantly share code, notes, and snippets.

View benoitjadinon's full-sized avatar

Benoit Jadinon benoitjadinon

View GitHub Profile
@praeclarum
praeclarum / TableViewController.cs
Last active January 5, 2021 14:31
All the boilerplate code needed to get a custom iOS UITableViewController up and running in C#
public class TableViewController : UITableViewController
{
static readonly NSString CellId = new NSString ("C");
readonly TableViewSource source = new TableViewSource ();
readonly List<string> rows = new List<string> ();
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
@paulpatarinski
paulpatarinski / XamFormsBindableProp
Created February 17, 2015 16:49
Xamarin Forms Bindable Property Resharper Template
public static readonly BindableProperty $propertyName$Property =
BindableProperty.Create("$propertyName$", typeof($propType$), typeof($controlType$), default($propType$));
public $propType$ $propertyName$
{
get { return ($propType$)GetValue($propertyName$Property); }
set { SetValue($propertyName$Property, value); }
}
@blounty
blounty / Android-CustomMapRenderer.cs
Created February 17, 2015 04:59
Create mapping apps that have amazingly cool custom map tiles with Xamarin.Forms
using System;
using Xamarin.Forms.Maps.Android;
using Android.Gms.Maps;
using Android.Gms.Maps.Model;
using Xamarin.Forms;
using CustomMapTiles;
using CustomMapTiles.Droid.Renderers;
[assembly: ExportRenderer (typeof (CustomMap), typeof (CustomMapRenderer))]
namespace CustomMapTiles.Droid.Renderers
@foxxjnm
foxxjnm / Blur.cs
Created February 16, 2015 15:58
Xamarin.iOS Image Blur
public static UIImage Blur(this UIImage image, float blurRadius = 25f)
{
if (image != null)
{
// Create a new blurred image.
var imageToBlur = new CIImage (image);
var blur = new CIGaussianBlur ();
blur.Image = imageToBlur;
blur.Radius = blurRadius;
@hjerpbakk
hjerpbakk / ColorUtils.cs
Created February 15, 2015 18:37
Get the color given a ratio between a start and end color. From: http://www.hjerpbakk.com/blog/2015/2/15/gradient-colors-on-ios
public static UIColor ColorForRatio(float[] startColor, float[] endColor, float colorRatio) {
return UIColor.FromRGB(startColor[0] + (endColor[0] - startColor[0]) * colorRatio,
startColor[1] + (endColor[1] - startColor[1]) * colorRatio,
startColor[2] + (endColor[2] - startColor[2]) * colorRatio);
}
@kpespisa
kpespisa / ToSafeString() extension method
Created February 13, 2015 21:56
ToSafeString() extension method to get an object's string representation or the empty string if the object is null
public static string ToSafeString(this object obj)
{
if (obj == null)
{
return string.Empty;
}
return obj.ToString();
}
@kpespisa
kpespisa / GetValueOrDefault() extension for dictionaries
Created February 13, 2015 21:47
GetValueOrDefault() extension method for Dictionaries
public static TValue GetValueOrDefault<TKey, TValue> (this IDictionary<TKey, TValue> dictionary, TKey key)
{
TValue ret;
dictionary.TryGetValue(key, out ret);
return ret;
}
Snippet Name: iOS Utils
Platform: Xamarin.iOS
Function: Check if running iOS 8, is phone, is tall, and envoke on UI Thread
Snippet:
public static class Utils
{
public static NSObject Invoker;
@aliozgur
aliozgur / FileSystemHelper.iOS.cs
Created December 10, 2014 11:01
Xamarin.Forms : File service to save/load your objects as Json
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using MonoTouch.UIKit;
using System.Collections;
using System.Collections.Generic;
using MonoTouch.Foundation;
/// <summary>
@hjerpbakk
hjerpbakk / CustomerFeelingSheet.cs
Last active August 29, 2015 14:10
Using a TaskCompletionSource to enable async and await together with UIAlertController. From: http://www.hjerpbakk.com/blog/2014/11/23/from-uialertview-to-uialertcontroller-using-xamarin-and-async-await
public static class CustomerFeelingSheet {
public static Task<CustomerFeeling> ShowRatingDialogAsync(UIViewController parent) {
var taskCompletionSource = new TaskCompletionSource<CustomerFeeling>();
var alert = UIAlertController.Create("howDoYouFeel".T(), null, UIAlertControllerStyle.ActionSheet);
alert.AddAction(UIAlertAction.Create("likeIt".T(), UIAlertActionStyle.Default,
a => taskCompletionSource.SetResult(CustomerFeeling.LikeIt)));
alert.AddAction(UIAlertAction.Create("couldBeBetter".T(), UIAlertActionStyle.Default,
a => taskCompletionSource.SetResult(CustomerFeeling.CouldBeBetter)));