iOSGraphics


Warning

This item was deprecated in version 2020r2. Please use Graphics as a replacement.

Description

Used to draw text, lines, rectangle and images.

Methods

Name

Parameters

Returns

Shared

ClipToPath

path As GraphicsPath

ClipToRect

x As Double, y As Double, width As Double, height As Double

DrawLine

x1 As Double, y1 As Double, x2 As Double, y2 As Double

DrawOval

x As Double, y As Double, width As Double, height As Double

DrawPath

path As GraphicsPath

DrawRect

x As Double, y As Double, width As Double, height As Double

DrawRoundRect

x As Double, y As Double, width As Double, height As Double, cornerWidth As Double, cornerHeight As Double

DrawTextBlock

value As String, x As Double, y As Double, maxWidth As Double = -1.0, maxHeight As Double = -1.0, alignment As iOSTextAlignment = iOSTextAlignment.Left, truncateLastLine As Boolean = False

DrawTextLine

value As String, x As Double, y As Double, maxWidth As Double = -1.0, alignment As iOSTextAlignment = iOSTextAlignment.Left, truncate As Boolean = False

FillOval

x As Double, y As Double, width As Double, height As Double

FillPath

path As GraphicsPath

FillRect

x As Double, y As Double, width As Double, height As Double

FillRoundRect

x As Double, y As Double, width As Double, height As Double, cornerWidth As Double, cornerHeight As Double

RestoreState

SaveState

Scale

scaleX As Double, scaleY As Double

TextBlockSize

value As String, maxWidth As Double = -1.0, maxHeight As Double = -1.0, alignment As iOSTextAlignment = iOSTextAlignment.Left, truncateLastLine As Boolean = False

Size

TextLineSize

value As String, maxWidth As Double = -1.0, alignment As iOSTextAlignment = iOSTextAlignment.Left, truncate As Boolean = False

Size

Translate

translateX As Double, translateY As Double

Property descriptions


iOSGraphics.Alpha

Alpha As Double

The Alpha value, which ranges from 0.0 (transparent) to 1.0 (opaque).

From within an iOSCanvas event handler:

g.Alpha = 0.5

iOSGraphics.AntiAlias

AntiAlias As Boolean

Specifies whether anti-aliasing is used. The default is True.

From within an iOSCanvas.Paint event handler:

g.AntiAlias = False

iOSGraphics.FillColor

FillColor As Color

The color used when drawing filled shapes and text.

From within an iOSCanvas event handler:

g.FillColor = Color.RGB(0, 0, 255) ' Blue

iOSGraphics.Handle

Handle As Ptr

The handle for the CGContextRef used by the graphics object.

This property is read-only.


iOSGraphics.Height

Height As Integer

The height of the graphics area, in points.

This property is read-only.

From within an iOSCanvas.Paint event handler:

g.LineColor = Color.Blue
g.DrawLine(0, 0, g.Width, g.Height)

iOSGraphics.LineColor

LineColor As Color

The color to use when drawing lines and shapes.

From within an iOSCanvas event handler:

g.LineColor = Color.Blue
g.DrawLine(0, 0, g.Width, g.Height)

iOSGraphics.LineWidth

LineWidth As Double

The width (in points) to use when drawing lines and shapes.

g.LineWidth = 10
g.DrawLine(0, 20, 50, 20)

iOSGraphics.TextFont

TextFont As iOSFont

The font to use when drawing text.

From within an iOSCanvas event handler:

g.TextFont = New iOSFont("Helvetica Neue", 12)
g.FillColor = Color.Blue
g.DrawTextBlock("Hello, World!", 30, 30)

iOSGraphics.TextUnderline

TextUnderline As Boolean

Indicates if drawn text should be underlined.

From within an iOSCanvas event handler:

g.TextFont = New iOSFont("Helvetica Neue", 12)
g.TextUnderline = True
g.DrawTextBlock("Hello, World!", 30, 30)

iOSGraphics.Width

Width As Integer

The width of the graphics area, in points.

This property is read-only.

From within an iOSCanvas event handler:

g.LineColor = Color.Blue
g.DrawLine(0, 0, g.Width, g.Height)

Method descriptions


iOSGraphics.ClipToPath

ClipToPath(path As GraphicsPath)

Clips the drawing to the specified path.

From within an iOSCanvas event handler:

' Clip to an iOSPath
' Path is a triangle
Var p As New iOSPath
p.MoveToPoint(0, 0) ' Start location
p.LineToPoint(20, 44)
p.LineToPoint(40, 0)
p.LineToPoint(0, 0)

g.ClipToPath(p)
g.FillOval(0, 0, 50, 50)

iOSGraphics.ClipToRect

ClipToRect(x As Double, y As Double, width As Double, height As Double)

Clips the drawing to the specified rectangle.

From within an iOSCanvas.Paint event handler:

' The part of the circle drawn outside the clip area
' is not displayed.
g.ClipToRect(0, 0, 50, 50)

g.FillColor = Color.Blue
g.FillOval(25, 25, 50, 50)

iOSGraphics.DrawLine

DrawLine(x1 As Double, y1 As Double, x2 As Double, y2 As Double)

Draws a line from x1, y1 to x2, y2.

From within an iOSCanvas.Paint event handler:

g.LineColor = Color.Blue
g.DrawLine(0, 0, g.Width, g.Height)

iOSGraphics.DrawOval

DrawOval(x As Double, y As Double, width As Double, height As Double)

Draws an oval where x and y are the top left corner. If width and height are the same, then a circle is drawn.

From within an iOSCanvas.Paint event handler:

g.DrawOval(50, 50, 25, 25)

' Draw circle in center of graphics area
Const kSize As Integer = 100
g.DrawOval((g.Width - kSize) / 2, (g.Height - kSize) / 2, kSize, kSize)

iOSGraphics.DrawPath

DrawPath(path As GraphicsPath)

Draws the specified path.

From within an iOSCanvas event handler:

' Draw a triangle
Var p As New iOSPath
p.MoveToPoint(0, 0) ' Start location
p.LineToPoint(20, 44)
p.LineToPoint(40, 0)
p.LineToPoint(0, 0)

g.LineColor = Color.Blue
g.DrawPath(p)

iOSGraphics.DrawRect

DrawRect(x As Double, y As Double, width As Double, height As Double)

Draws a rectangle.

From within an iOSCanvas event handler:

g.LineColor = Color.Blue
g.DrawRect(10, 10, 20, 20)

iOSGraphics.DrawRoundRect

DrawRoundRect(x As Double, y As Double, width As Double, height As Double, cornerWidth As Double, cornerHeight As Double)

Draws a rounded rectangle.

From within an iOSCanvas event handler:

g.LineColor = Color.Blue
g.DrawRoundRect(10, 10, 50, 50, 5, 5)

iOSGraphics.DrawTextBlock

DrawTextBlock(value As String, x As Double, y As Double, maxWidth As Double = -1.0, maxHeight As Double = -1.0, alignment As iOSTextAlignment = iOSTextAlignment.Left, truncateLastLine As Boolean = False)

Draws a block of text.

From within an iOSCanvas event handler:

g.FillColor = Color.Blue
Var t As Text
t = "How much wood would a woodchuck chuck if a woodchuck could chuck wood?"
g.DrawTextBlock(t, 0, 10, g.Width, g.Height, iOSTextAlignment.Left, False)

iOSGraphics.DrawTextLine

DrawTextLine(value As String, x As Double, y As Double, maxWidth As Double = -1.0, alignment As iOSTextAlignment = iOSTextAlignment.Left, truncate As Boolean = False)

Draws a single line of text.

From within an iOSCanvas event handler:

g.FillColor = Color.Blue
Var t As Text
t = "Hello, World!"
g.DrawTextLine(t, 0, 10, -1, iOSTextAlignment.Left, False) ' Left-aligned
g.DrawTextLine(t, 0, 10, -1, iOSTextAlignment.Center, False) ' Centered
g.DrawTextLine(t, 0, 10, 100, iOSTextAlignment.Right, False) ' Right-aligned

iOSGraphics.FillOval

FillOval(x As Double, y As Double, width As Double, height As Double)

Draws an oval, filling it with the FillColor.

From within an iOSCanvas event handler:

g.FillColor = Color.Blue
g.FillOval(10, 10, 20, 20)

iOSGraphics.FillPath

FillPath(path As GraphicsPath)

Draws a path, filling it with the FillColor.

From within an iOSCanvas event handler:

' Draw a triangle
Var p As New iOSPath
p.MoveToPoint(0, 0) ' Start location
p.LineToPoint(20, 44)
p.LineToPoint(40, 0)
p.LineToPoint(0, 0)

g.FillColor = Color.Blue
g.FillPath(p)

iOSGraphics.FillRect

FillRect(x As Double, y As Double, width As Double, height As Double)

Draws a rectangle, filling it with the FillColor.

From within an iOSCanvas event handler:

g.FillColor = Color.Blue
g.FillRect(10, 10, 20, 20)

iOSGraphics.FillRoundRect

FillRoundRect(x As Double, y As Double, width As Double, height As Double, cornerWidth As Double, cornerHeight As Double)

Draws a rounded rectangle, filling it with the FillColor.

From within an iOSCanvas event handler:

g.FillColor = Color.Blue
g.FillRoundRect(10, 10, 50, 50, 5, 5)

iOSGraphics.RestoreState

RestoreState

Restores graphics context previously saved with SaveState.

From within an iOSCanvas event handler:

g.FillColor = Color.Blue
g.FillRect(10, 10, 20, 20)

g.SaveState
g.FillColor = Color.Red
g.FillRect(50, 50, 20, 20)

' Restore to state where FillColor is Blue
g.RestoreState
g.FillRect(10, 50, 20, 20)

iOSGraphics.SaveState

SaveState

Saves graphics state of the graphics context so that it can be restored later.

These values are saved with SaveState and are restored when you call RestoreState:

  • Translation

  • Clip region

  • LineWidth

  • AntiAlias

  • FillColor

  • LineColor

  • Alpha value

  • TextFont

  • TextUnderline

  • Rotation

From within an iOSCanvas event handler:

g.FillColor = Color.Blue
g.FillRect(10, 10, 20, 20)

g.SaveState
g.FillColor = Color.Red
g.FillRect(50, 50, 20, 20)

' Restore to state where FillColor is Blue
g.RestoreState
g.FillRect(10, 50, 20, 20)

iOSGraphics.Scale

Scale(scaleX As Double, scaleY As Double)

Sets the scale for the graphics context as specified scaleX and scaleY. This only affects subsequent drawing. Any drawing done before the Scale method is called is not scaled.

From within an iOSCanvas event handler:

g.Scale(2.0, 4.0)
g.FillColor = Color.Blue
g.FillRect(10, 10, 10, 10) ' The squares scales to a rectangle

iOSGraphics.TextBlockSize

TextBlockSize(value As String, maxWidth As Double = -1.0, maxHeight As Double = -1.0, alignment As iOSTextAlignment = iOSTextAlignment.Left, truncateLastLine As Boolean = False) As Size

Calculates the size of a text as it would appear using DrawTextBlock.

Get the text block size of left-aligned text:

Var tbs As Size
tbs = g.TextBlockSize("Hello, world!", -1, -1, iOSTextAlignment.Left, False)

iOSGraphics.TextLineSize

TextLineSize(value As String, maxWidth As Double = -1.0, alignment As iOSTextAlignment = iOSTextAlignment.Left, truncate As Boolean = False) As Size

Calculates the size of a text as it would appear using DrawTextLine.

Get the text line size of left-aligned text:

Var tls As Size
tls = g.TextLineSize("Hello, world!", -1, iOSTextAlignment.Left, False)

iOSGraphics.Translate

Translate(translateX As Double, translateY As Double)

Translates the origin point by the specified translateX and translateY values. Useful with Rotate.

From within an iOSCanvas event handler:

' Rotate square in center of graphics area
Const Pi = 3.14159
g.Translate(g.Width / 2, g.Height / 2)
g.Rotate(Pi / 4) ' 45 degrees or 1/8 of a circle
g.FillColor = Color.Blue
g.FillRect(10, 10, 50, 50)

Notes

You cannot instantiate iOSGraphics. You can get an iOSGraphics instance from either an MobileCanvas or an Picture.

Changing the graphics state only affects subsequent drawing commands.

Compatibility

iOS projects on the iOS operating system.

See also

Object parent class; Picture, Picture, GraphicsPath classes; MobileCanvas control