Xamarin.Macで、NSViewに文字列を描画する

NSViewに文字列を描画するサンプルアプリケーションです。

ソースコードはこちら

NSViewのDrawRect()メソッドで、NSMutableAttributedString()に描画する文字の設定を行い、DrawAtPoint()で描画する座標を指定します。

public partial class MyView : NSView
{
    public override void DrawRect(CoreGraphics.CGRect dirtyRect)
    {
        NSMutableAttributedString attributes = new NSMutableAttributedString("Hello, World.");
        attributes.AddAttribute(NSStringAttributeKey.Font, NSFont.FromFontName("Helvetica", 96), new NSRange(0, 13));
        attributes.AddAttribute(NSStringAttributeKey.ForegroundColor, NSColor.Brown, new NSRange(0, 13));
        attributes.DrawAtPoint(new CoreGraphics.CGPoint(0, 0));
    }
}

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください