本文整理汇总了C#中CGPath.AddRect方法的典型用法代码示例。如果您正苦于以下问题:C# CGPath.AddRect方法的具体用法?C# CGPath.AddRect怎么用?C# CGPath.AddRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGPath
的用法示例。
在下文中一共展示了CGPath.AddRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(CGRect rect)
{
//get graphics context
using (CGContext g = UIGraphics.GetCurrentContext())
{
//set up drawing attributes
UIColor.Black.SetFill();
//create geometry
_overlay = new CGPath();
_overlay.AddRect(new RectangleF(0f, 0f, _width, _height));
if(_isRound)
_overlay.AddEllipseInRect(new RectangleF((float)_rect.X, (float)_rect.Y, (float)_rect.Width, (float)_rect.Height));
else
_overlay.AddRect(new RectangleF((float)_rect.X, (float)_rect.Y, (float)_rect.Width, (float)_rect.Height));
g.SetStrokeColor(UIColor.Clear.CGColor);
g.SetAlpha(0.6f);
//add geometry to graphics context and draw it
g.AddPath(_overlay);
g.DrawPath(CGPathDrawingMode.EOFillStroke);
}
}
示例2: Draw
public override void Draw(CGRect rect)
{
//get graphics context
using (CGContext g = UIGraphics.GetCurrentContext())
{
g.SetLineWidth(_lineWidth);
//set up drawing attributes
UIColor.Clear.SetFill();
if (_isRound)
{
var circle = new CGPath();
var circleSize = rect.Size.Width / 2;
circle.AddArc(circleSize, circleSize, circleSize, 0, endangle, true);
Console.WriteLine("circleSize: {0}", circleSize);
g.AddPath(circle);
}
else
{
//create geometry
var rectangle = new CGPath();
rectangle.AddRect(new RectangleF(0f, 0f, (float)rect.Size.Width, (float)rect.Size.Height));
rectangle.CloseSubpath();
//add geometry to graphics context and draw it
g.AddPath(rectangle);
}
g.SetStrokeColor(_color.CGColor);
g.SetAlpha(_transparancy);
g.DrawPath(CGPathDrawingMode.Stroke);
}
}
示例3: CreateShape
public override void CreateShape(CGPath path, CGContext gctx)
{
path.AddRect (new RectangleF (_origin, new SizeF (100, 100)));
gctx.AddPath (path);
gctx.DrawPath (CGPathDrawingMode.FillStroke);
}
示例4: Draw
// rect changes depending on if the whole view is being redrawn, or just a section
public override void Draw (CGRect rect)
{
Console.WriteLine ("Draw() Called");
base.Draw (rect);
using (CGContext context = UIGraphics.GetCurrentContext ()) {
// draw a rectangle using a path
myRectangleButtonPath = new CGPath ();
myRectangleButtonPath.AddRect (new CGRect (new CGPoint (100, 10), new CGSize (200, 400)));
context.AddPath (myRectangleButtonPath);
context.DrawPath (CGPathDrawingMode.Stroke);
}
}
示例5: Draw
public override void Draw(RectangleF rect)
{
base.Draw (rect);
using (CGContext gctx = UIGraphics.GetCurrentContext()) {
gctx.SetLineWidth(3);
UIColor.Clear.SetFill();
StrokeColor.SetStroke();
path = new CGPath ();
path.AddRect(rect);
path.CloseSubpath();
gctx.AddPath(path);
gctx.DrawPath(CGPathDrawingMode.FillStroke);
}
}
示例6: Draw
public override void Draw(RectangleF rect)
{
using (var g = UIGraphics.GetCurrentContext())
{
g.SetLineWidth(10);
UIColor.FromRGB(64,30,168).SetStroke ();
UIColor.Clear.SetFill ();
//create geometry
var path = new CGPath ();
path.AddRect (rect);
path.CloseSubpath();
//add geometry to graphics context and draw it
g.AddPath(path);
g.DrawPath(CGPathDrawingMode.Stroke);
}
}
示例7: Draw
public override void Draw(CGRect rect)
{
base.Draw (rect);
using (var g = UIGraphics.GetCurrentContext ()) {
g.SetFillColor (UIColor.Gray.CGColor);
g.FillRect (rect);
g.SetBlendMode (CGBlendMode.Clear);
UIColor.Clear.SetColor ();
var path = new CGPath ();
path.AddRect (new CGRect (origin, cropSize));
g.AddPath (path);
g.DrawPath (CGPathDrawingMode.Fill);
}
}
示例8: Draw
public override void Draw(System.Drawing.RectangleF rect)
{
base.Draw (rect);
CGContext context = UIGraphics.GetCurrentContext ();
// Apply a transform that flips the Y axis, since CT uses a different coords system
// context.TextMatrix = CGAffineTransform.MakeIdentity ();
// context.TranslateCTM (0, this.Bounds.Size.Height);
// context.ScaleCTM (1.0f, -1.0f);
CGPath path = new CGPath ();
path.AddRect (this.Bounds);
try {
CTFrame frame = Framesetter.GetFrame (new NSRange (0, this._text.Length), path, null);
frame.Draw (context);
} catch (Exception ex) {
Console.WriteLine (ex.Message);
}
}
示例9: StringSize
NativeSize StringSize (string str, int startIndex, int length)
{
if (str == null || length <= 0) return NativeSize.Empty;
using (var astr = new NSMutableAttributedString (str)) {
astr.AddAttributes (attrs, new NSRange (startIndex, length));
using (var fs = new CTFramesetter (astr)) {
using (var path = new CGPath ()) {
path.AddRect (new NativeRect (0, 0, 30000, attrs.Font.XHeightMetric * 10));
using (var f = fs.GetFrame (new NSRange (startIndex, length), path, null)) {
var line = f.GetLines () [0];
NativeValue a, d, l;
var tw = line.GetTypographicBounds (out a, out d, out l);
return new NativeSize ((float)tw, (a + d) * 1.2f);
}
}
}
}
}
示例10: DrawString
public void DrawString (string s, float x, float y)
{
if (string.IsNullOrEmpty (s))
return;
using (var astr = new NSMutableAttributedString (s)) {
astr.AddAttributes (_attrs, new NSRange (0, s.Length));
using (var fs = new CTFramesetter (astr)) {
using (var path = new CGPath ()) {
var h = _lastFont.Size * 2;
path.AddRect (new NativeRect (0, 0, s.Length * h, h));
using (var f = fs.GetFrame (new NSRange (0, 0), path, null)) {
var line = f.GetLines () [0];
NativeValue a, d, l;
line.GetTypographicBounds (out a, out d, out l);
_c.SaveState ();
_c.TranslateCTM (x, h + y - d);
_c.ScaleCTM (1, -1);
f.Draw (_c);
_c.RestoreState ();
}
}
}
}
// var c = _color;
// SetColor (Colors.Black);
// DrawRect (x, y, 100, _lastFont.Size, 1);
// SetColor (c);
}
示例11: newPathInRect
CGPath newPathInRect(RectangleF rect)
{
CGPath path = new CGPath ();
path.AddRect (rect);
return path;
}
示例12: Draw
public override void Draw(RectangleF rect)
{
//temp until I figure out why dthis doesn't work properly on iPad.
return;
if (_Cell != null)
{
CGContext context = UIGraphics.GetCurrentContext();
CGPath path;
var borderRect = rect;
if (_Cell.TableView.Style == UITableViewStyle.Grouped)
{
borderRect = _Cell.CalculateInnerRect();
path = _Cell.GetCellBorderPath(borderRect);
}
else
{
path = new CGPath();
path.AddRect(borderRect);
}
context.AddPath(path);
context.SetFillColor(_Cell.Element.Theme.DisabledColor.CGColor);
context.SetBlendMode(CGBlendMode.Overlay);
context.DrawPath(CGPathDrawingMode.Fill);
}
}
示例13: DrawContentView
public void DrawContentView()
{
if (!Highlighted)
{
var borderRect = Bounds;
var innerRect = CalculateInnerRect();
CGPath path = null;
var backgroundColor = TableView.BackgroundColor;
CGContext context = UIGraphics.GetCurrentContext();
context.SaveState();
context.SetFillColor(backgroundColor.CGColor);
if (TableView.Style == UITableViewStyle.Grouped)
{
borderRect = CalculateInnerRect();
path = GetCellBorderPath(borderRect);
}
else
{
path = new CGPath();
path.AddRect(borderRect);
}
context.AddPath(path);
context.Clip();
ShouldDrawBorder = false;
if (Element.Theme.DrawElementViewAction != null)
{
DrawElementView(innerRect, context);
}
context.RestoreState();
if (ShouldDrawBorder)
{
DrawBorder(context, path);
}
}
}
示例14: DrawRectangle
/// <summary>
/// Draws a rectangle.
/// </summary>
/// <param name="rect">The rectangle.</param>
/// <param name="fill">The fill color.</param>
/// <param name="stroke">The stroke color.</param>
/// <param name="thickness">The stroke thickness.</param>
public override void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness)
{
this.SetAlias(true);
var convertedRect = rect.ConvertAliased();
if (fill.IsVisible())
{
this.SetFill(fill);
using (var path = new CGPath())
{
path.AddRect(convertedRect);
this.gctx.AddPath(path);
}
this.gctx.DrawPath(CGPathDrawingMode.Fill);
}
if (stroke.IsVisible() && thickness > 0)
{
this.SetStroke(stroke, thickness);
using (var path = new CGPath())
{
path.AddRect(convertedRect);
this.gctx.AddPath(path);
}
this.gctx.DrawPath(CGPathDrawingMode.Stroke);
}
}
示例15: Draw
public override void Draw (RectangleF rect)
{
Console.WriteLine ("# Draw: rect={{X={0}, Y={1}, Width={2}, Height={3}}}", rect.X, rect.Y, rect.Width, rect.Height);
// Initialize a graphics context and set the text matrix to a known value
var context = UIGraphics.GetCurrentContext ();
// context.TextMatrix = CGAffineTransform.MakeIdentity ();
context.TextMatrix = CGAffineTransform.MakeScale (1f, -1f);
// initialize a rectangular path
var path = new CGPath ();
// path.AddRect (new RectangleF (10.0f, 10.0f, 200.0f, 30.0f));
path.AddRect (rect);
RectangleF r;
Console.WriteLine ("path.IsRect={0}; Width={1}, Height={2}", path.IsRect (out r), r.Width, r.Height);
// initialize an attributed string
var attrString = new NSMutableAttributedString ("We hold this truth to be self evident, that everyone is created equal.");
// use a red font for the first 50 chars
attrString.AddAttributes(new CTStringAttributes () {
ForegroundColor = new CGColor (
CGColorSpace.CreateDeviceRGB(),
new[]{1.0f, 0.0f, 0.0f, 0.8f}
),
}, new NSRange (0, 50));
// Create the framesetter with the attributed string
using (var framesetter = new CTFramesetter (attrString)) {
NSRange fitRange;
var size = framesetter.SuggestFrameSize (new NSRange (), null, new SizeF (200f, 200f), out fitRange);
Console.WriteLine ("fitRange.Location={0}; fitRange.Length={1}", fitRange.Location, fitRange.Length);
Console.WriteLine ("Size: Width={0}; Height={1}", size.Width, size.Height);
// Create the frame and draw it into the graphics context
using (var frame = framesetter.GetFrame (new NSRange (0, 70), path, null))
frame.Draw (context);
context.ShowText ("hello, world!");
}
}