Create a gist now

Instantly share code, notes, and snippets.

How to create iOS's recipient bubbles in MonoTouch
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.IO;
namespace BubbleExample
{
public class RecipientBubble : UIView
{
public const string IMAGES_PATH = "Content/Images";
private static UIImage _backgroundImage;
private UILabel _titleLabel;
private UIImageView _backgroundView;
static RecipientBubble()
{
_backgroundImage = UIImage.FromFile("recipientbackground.png").StretchableImage(11, 0);
}
public RecipientBubble(string title)
{
_titleLabel = new UILabel(new RectangleF(0, -100, 10, 23));
_titleLabel.Font = UIFont.SystemFontOfSize(14);
_titleLabel.TextAlignment = UITextAlignment.Center;
_titleLabel.Text = title;
_titleLabel.SizeToFit();
_titleLabel.Frame = new RectangleF(0, 0, _titleLabel.Frame.Width + 20, 21);
_titleLabel.TextColor = UIColor.White;
_titleLabel.BackgroundColor = UIColor.Clear;
AddSubview(_titleLabel);
_backgroundView = new UIImageView(_backgroundImage);
_backgroundView.Frame = new RectangleF(0, 0, _titleLabel.Frame.Width, 23);
InsertSubviewBelow(_backgroundView, _titleLabel);
SizeToFit();
}
public SizeF ComputedSize
{
get
{
return _titleLabel.Frame.Size;
}
}
}
}
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace BubbleExample
{
public class ViewController : UIViewController
{
public ViewController()
{
}
public override void LoadView()
{
base.LoadView();
var recipientBubble = new RecipientBubble("Capt. Morgan");
recipientBubble.Frame = new RectangleF(new PointF(10, 10), recipientBubble.ComputedSize);
View.AddSubview(recipientBubble);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment