Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

id title brief samplecode sdk
Draw Unicode Text with CoreText
This recipe shows how to draw text using Core Text.


  1. In a UIView subclass override Draw and set graphics context state.
var gctx = UIGraphics.GetCurrentContext ();
gctx.TranslateCTM (10, 0.5f * Bounds.Height);
gctx.ScaleCTM (1, -1);
gctx.RotateCTM ((float)Math.PI * 315 / 180);
gctx.SetFillColor (UIColor.Green.CGColor);
  1. Create a Unicode text string.
string someText = "你好世界";
  1. Create an NSAttributedString.
var attributedString = new NSAttributedString (someText,
       new CTStringAttributes{
	      ForegroundColorFromContext =  true,
	      Font = new CTFont ("Arial", 24)
  1. Pass the NSAttributedString to a CTLine and draw the CTLine.
using (var textLine = new CTLine (attributedString)) {
       textLine.Draw (gctx);

Additional Information

You can draw text using the Core Text framework by creating an NSAttributedString instance; passing it to a CTLine instance and calling Draw on the CTLine. Otherwise, normal Core Graphics techniques such as obtaining a graphics context and manipulating the current transformation matrix apply. This example draws text of a given font and color and rotates it as shown above.

You can’t perform that action at this time.