Skip to content

Instantly share code, notes, and snippets.

async void Demo ()
{
switch (await ShowAlert ("Title", "Message", "Ok", "Cancel")){
case 0: // Ok
....
case 1: // Cancel
....
}
}
@dannycabrera
dannycabrera / AppDelegate
Created December 5, 2013 04:39
AudioQueueOfflineRenderDemo AppDelegate test
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using MonoTouch;
using MonoTouch.AVFoundation;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
@dannycabrera
dannycabrera / Xamarin.iOS AudioTrim Method
Created June 13, 2013 21:20
Xamarin.iOS AudioTrim Method
using System;
using System.IO;
using MonoTouch.Foundation;
using MonoTouch.AVFoundation;
using MonoTouch.CoreMedia;
namespace TestProject.Common
{
public class AudioTrim
{
@dannycabrera
dannycabrera / GetVideoThumbnail.cs
Created March 1, 2016 15:49
Xamarin.iOS get video thumbnail
private UIImage GetVideoThumbnail(string path)
{
try {
CMTime actualTime;
NSError outError;
using (var asset = AVAsset.FromUrl (NSUrl.FromFilename (path)))
using (var imageGen = new AVAssetImageGenerator (asset))
using (var imageRef = imageGen.CopyCGImageAtTime (new CMTime (1, 1), out actualTime, out outError)) {
return UIImage.FromImage (imageRef);
}
@dannycabrera
dannycabrera / LoadUITextViewWithRTF.cs
Created October 27, 2016 13:32
Load RTF document into UITextView using Xamarin.iOS
NSError error = null;
var attributedString = new NSAttributedString (new NSUrl ("...Sample.rtf", false), null, ref error);
var attributedTextHolder = new NSMutableAttributedString (attributedString);
textView.AllowsEditingTextAttributes = true;
textView.AttributedText = attributedTextHolder;
@dannycabrera
dannycabrera / SaveRTFFromUITextView.cs
Last active October 27, 2016 13:38
Save RTF from UITextView using NSFileWrapper on Xamarin.iOS
NSError error1 = null;
NSError error2 = null;
var atts = new NSAttributedStringDocumentAttributes ();
atts.DocumentType = NSDocumentType.RTF;
using (var wrapper = textView.AttributedText.GetFileWrapperFromRange (new NSRange (0, textView.Text.Length), atts, ref error1))
{
wrapper.Write (new NSUrl ("...Edited.rtf", false), NSFileWrapperWritingOptions.Atomic, new NSUrl ("...Sample.rtf", false), out error2);
}
@dannycabrera
dannycabrera / AirPrint.cs
Created November 22, 2016 21:00
Printing PDF with UIKit.UIPrint on Xamarin.iOS
using UIKit;
void AirPrint (CGRect frame, string pdfOrImageToPrint)
{
var printer = UIPrintInteractionController.SharedPrintController;
if (printer == null) {
Console.WriteLine("Unable to print at this time.");
} else {
var printInfo = UIPrintInfo.PrintInfo;
@dannycabrera
dannycabrera / LevenshteinDistance.cs
Created December 16, 2016 16:05
LevenshteinDistance computation
using System;
/// <summary>
/// Contains approximate string matching
/// </summary>
static class LevenshteinDistance
{
/// <summary>
/// Compute the distance between two strings.
/// </summary>
@dannycabrera
dannycabrera / Random.cs
Last active December 30, 2016 17:09
Random pastel color generator
using System;
using UIKit;
// based on http://blog.functionalfun.net/2008/07/random-pastel-colour-generator.html
public static UIColor RandomColor ()
{
Random random = new Random ();
// to create lighter colors:
// take a random integer between 0 & 128 (rather than between 0 and 255)

Keybase proof

I hereby claim:

  • I am dannycabrera on github.
  • I am dannyc (https://keybase.io/dannyc) on keybase.
  • I have a public key ASAQdo3ygYwQ9-kyIy9iP8hX1969zoXtQFb4vorZMYtX5go

To claim this, I am signing this object: