Skip to content

Instantly share code, notes, and snippets.

@Digitalchemy
Digitalchemy / EnumPhoneFonts.cs
Created February 4, 2011 06:33
Monotouch method to enumerate loaded iPhone fonts to debug output for diagnostic purposes
void EnumerateLoadedFonts()
{
foreach (string family in UIFont.FamilyNames)
{
Debug.WriteLine("Family : " + family);
foreach (string font in UIFont.FontNamesForFamilyName(family))
{
Debug.WriteLine(" Font : " + font);
}
@Digitalchemy
Digitalchemy / CropImage.cs
Created February 6, 2011 06:21
iOS: Crop a UIImage to the specified Rect
// Crop a UIImage to the specified cropRect
public UIImage CropImage(UIImage image, RectangleF cropRect)
{
UIGraphics.BeginImageContextWithOptions(cropRect.Size, false, 0);
var context = UIGraphics.GetCurrentContext();
context.TranslateCTM(0.0f, image.Size.Height);
context.ScaleCTM(1.0f, -1.0f);
context.DrawImage(new RectangleF(0, 0, image.Size.Width, image.Size.Height), image.CGImage);
context.ClipToRect(cropRect);
@Digitalchemy
Digitalchemy / ScaleUIImage.cs
Created March 1, 2011 02:26
Scale a UIImage to fill both dimensions of the specified cropRect
public UIImage ScaleImageToFillCropRect(UIImage image, RectangleF cropRect)
{
float frameXToYScale = cropRect.Height / cropRect.Width;
float imageXToYScale = image.Size.Height / image.Size.Width;
float scaleFactor;
// Decide if X or Y should be scaled
if (imageXToYScale > frameXToYScale)
{
// Match X dimension of frame