本文整理汇总了C#中CGContext.Clip方法的典型用法代码示例。如果您正苦于以下问题:C# CGContext.Clip方法的具体用法?C# CGContext.Clip怎么用?C# CGContext.Clip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGContext
的用法示例。
在下文中一共展示了CGContext.Clip方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillRect
public static void FillRect(CGContext context, RectangleF rect, CGColor color)
{
context.SaveState();
context.AddRect(rect);
context.Clip();
context.SetFillColor(color);
context.FillRect(rect);
context.RestoreState();
}
示例2: DrawInContext
public override void DrawInContext(CGContext ctx)
{
base.DrawInContext (ctx);
// clip
var cornerRadius = Bounds.Height / 2.0f;
UIBezierPath switchOutline = UIBezierPath.FromRoundedRect( (CGRect)Bounds, (nfloat)cornerRadius);
ctx.AddPath (switchOutline.CGPath);
ctx.Clip ();
// 1) fill the track
ctx.SetFillColor (UIColor.Green.CGColor);
ctx.AddPath(switchOutline.CGPath);
ctx.FillPath ();
// 2) fill the highlighed range //Skipped for demo
// 3) add a highlight over the track
CGRect highlight = new CGRect(cornerRadius/2, Bounds.Height/2,
Bounds.Width - cornerRadius, Bounds.Height/2);
UIBezierPath highlightPath = UIBezierPath.FromRoundedRect ((CGRect)highlight, (nfloat)highlight.Height / 2.0f);
ctx.AddPath(highlightPath.CGPath);
ctx.SetFillColor( UIColor.FromWhiteAlpha((nfloat)1.0f, (nfloat)0.4f).CGColor);
ctx.FillPath ();
// 4) inner shadow
ctx.SetShadow( new CGSize(0f, 2.0f), 3.0f, UIColor.Gray.CGColor);
ctx.AddPath (switchOutline.CGPath);
ctx.SetStrokeColor(UIColor.Gray.CGColor);
ctx.StrokePath ();
// 5) outline the track
ctx.AddPath( switchOutline.CGPath);
ctx.SetStrokeColor(UIColor.Black.CGColor);
ctx.SetLineWidth ((nfloat)0.5f);
ctx.StrokePath ();
//
// ctx.SetFillColor (UIColor.Blue.CGColor);
// ctx.FillRect (Bounds);
}
示例3: DrawInContext
public override void DrawInContext(CGContext ctx)
{
base.DrawInContext (ctx);
// clip
var cornerRadius = Bounds.Height * Slider.Curvaceousness / 2.0f;
UIBezierPath switchOutline = UIBezierPath.FromRoundedRect( (CGRect)Bounds, (nfloat)cornerRadius);
ctx.AddPath (switchOutline.CGPath);
ctx.Clip ();
// 1) fill the track
ctx.SetFillColor (Slider.TrackColor.CGColor);
ctx.AddPath(switchOutline.CGPath);
ctx.FillPath ();
// 2) fill the highlighed range
ctx.SetFillColor(Slider.TrackHighlightColor.CGColor);
var lower = Slider.positionForValue (Slider.LowValue);
var higher = Slider.positionForValue(Slider.HighValue);
ctx.FillRect((CGRect)new CGRect(lower, 0, higher - lower, Bounds.Height));
// 3) add a highlight over the track
CGRect highlight = new CGRect(cornerRadius/2, Bounds.Height/2,
Bounds.Width - cornerRadius, Bounds.Height/2);
UIBezierPath highlightPath = UIBezierPath.FromRoundedRect ((CGRect)highlight, (nfloat)highlight.Height * Slider.Curvaceousness / 2.0f);
ctx.AddPath(highlightPath.CGPath);
ctx.SetFillColor( UIColor.FromWhiteAlpha((nfloat)1.0f, (nfloat)0.4f).CGColor);
ctx.FillPath ();
// 4) inner shadow
ctx.SetShadow( new CGSize(0f, 2.0f), 3.0f, UIColor.Gray.CGColor);
ctx.AddPath (switchOutline.CGPath);
ctx.SetStrokeColor(UIColor.Gray.CGColor);
ctx.StrokePath ();
// 5) outline the track
ctx.AddPath( switchOutline.CGPath);
ctx.SetStrokeColor(UIColor.Black.CGColor);
ctx.SetLineWidth ((nfloat)0.5f);
ctx.StrokePath ();
}
示例4: DrawPhoto
void DrawPhoto(CGContext ctx)
{
ctx.SaveState ();
ctx.AddPath (PhotoBorder);
ctx.Clip ();
Photograph.Draw (PhotoRect);
ctx.AddPath (PhotoBorder);
ctx.SetStrokeColor (0.5f, 0.5f, 0.5f, 1.0f);
ctx.SetLineWidth (0.5f);
ctx.StrokePath ();
ctx.RestoreState ();
}
示例5: DrawAddPhotoButton
void DrawAddPhotoButton(CGContext ctx)
{
UIColor background = pressed ? HighlightedButtonColor : NormalButtonColor;
RectangleF bounds = PhotoRect;
float alpha = 1.0f;
ctx.SaveState ();
ctx.AddPath (PhotoBorder);
ctx.Clip ();
using (var cs = CGColorSpace.CreateDeviceRGB ()) {
var bottomCenter = new PointF (bounds.GetMidX (), bounds.GetMaxY ());
var topCenter = new PointF (bounds.GetMidX (), bounds.Y);
float[] gradColors;
CGPath container;
gradColors = new [] { 0.23f, 0.23f, 0.23f, alpha, 0.67f, 0.67f, 0.67f, alpha };
using (var gradient = new CGGradient (cs, gradColors, new [] { 0.0f, 1.0f })) {
ctx.DrawLinearGradient (gradient, topCenter, bottomCenter, 0);
}
var bg = bounds.Inset (1.0f, 1.0f);
container = GraphicsUtil.MakeRoundedRectPath (bg, 13.5f);
ctx.AddPath (container);
ctx.Clip ();
background.SetFill ();
ctx.FillRect (bg);
gradColors = new [] {
0.0f, 0.0f, 0.0f, 0.75f,
0.0f, 0.0f, 0.0f, 0.65f,
0.0f, 0.0f, 0.0f, 0.35f,
0.0f, 0.0f, 0.0f, 0.05f
};
using (var gradient = new CGGradient (cs, gradColors, new float [] { 0.0f, 0.1f, 0.4f, 1.0f })) {
ctx.DrawLinearGradient (gradient, topCenter, bottomCenter, 0);
}
}
//ctx.AddPath (PhotoBorder);
//ctx.SetStrokeColor (0.5f, 0.5f, 0.5f, 1.0f);
//ctx.SetLineWidth (0.5f);
//ctx.StrokePath ();
ctx.RestoreState ();
}
示例6: DrawShine
private void DrawShine(CGContext context, RectangleF rect)
{
context.SaveState ();
context.BeginPath ();
var maxY = MakePath (context, rect);
context.Clip ();
/*var locations = new float[] { 0.0f, 0.5f };
var components = new float[] { 0.92f, 0.92f, 0.92f, 1.0f, 0.82f, 0.82f, 0.82f, 0.4f };*/
var locations = new float[] { 0f, 0.4f, 0.5f, 0.5f, 0.6f, 1.0f };
var colors = new UIColor[] {
UIColor.FromWhiteAlpha (1.0f, 0.885f),
UIColor.FromWhiteAlpha (1.0f, 0.45f),
UIColor.FromWhiteAlpha (1.0f, 0.23f),
UIColor.FromWhiteAlpha (1.0f, 0.10f),
UIColor.FromRGBA (0f, 0f, 0f, 0.13f),
UIColor.FromRGBA (0f, 0f, 0f, 0.13f)
};
var components = GetComponents (colors);
var darkLoc = new float[] { 0.5f, 1.0f };
var darkComp = new float[] { 0.08f, 0.08f, 0.08f, 0.6f, 0.18f, 0.18f, 0.18f, 0.2f };
using (var cspace = CGColorSpace.CreateDeviceRGB ())
using (var darkGrad = new CGGradient (cspace, darkComp, darkLoc))
using (var gradient = new CGGradient (cspace, components, locations)) {
PointF sPoint = new PointF (0f, 0f),
ePoint = new PointF (0f, maxY);
context.DrawLinearGradient (gradient, sPoint, ePoint, 0);
}
context.RestoreState ();
}
示例7: drawCenter
void drawCenter(CGContext contextRef, SizeF viewSize, PointF center)
{
int innerDiameter = (int)(Math.Min(viewSize.Width, viewSize.Height) - Theme.Thickness);
double innerRadius = innerDiameter / 2.0;
contextRef.SetLineWidth(Theme.Thickness);
RectangleF innerCircle = new RectangleF((float)(center.X - innerRadius), (float)(center.Y - innerRadius), (float)innerDiameter, (float)innerDiameter);
contextRef.AddEllipseInRect(innerCircle);
contextRef.Clip();
contextRef.ClearRect(innerCircle);
contextRef.SetFillColor(Theme.CenterColor.CGColor);
contextRef.FillRect(innerCircle);
}
示例8: FillGradient
public static void FillGradient(CGContext context, RectangleF rect, CGColor color1, CGColor color2)
{
CGGradient gradientBackground;
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
float[] locationListBackground = new float[] { 1.0f, 0.0f };
List<float> colorListBackground = new List<float>();
colorListBackground.AddRange(color1.Components);
colorListBackground.AddRange(color2.Components);
gradientBackground = new CGGradient(colorSpace, colorListBackground.ToArray(), locationListBackground);
context.SaveState();
context.AddRect(rect);
context.Clip();
//context.ScaleCTM(1, -1);
context.DrawLinearGradient(gradientBackground, new PointF(rect.X, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
context.RestoreState();
}
示例9: DrawLinearGradient
private void DrawLinearGradient(CGContext context, RectangleF rect, CGColor startColor, CGColor endColor)
{
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
float [] locations = { 0.0f, 1.0f };
CGColor [] colors = new CGColor[] { startColor, endColor };
CGGradient gradient = new CGGradient (colorSpace, colors, locations);
PointF startPoint = new PointF (rect.GetMidX (), rect.GetMinY ());
PointF endPoint = new PointF (rect.GetMidX (), rect.GetMaxY ());
context.SaveState ();
context.AddPath (UIBezierPath.FromRoundedRect (rect, 10).CGPath);
context.Clip ();
context.DrawLinearGradient (gradient, startPoint, endPoint, 0);
context.RestoreState ();
}
示例10: DrawInContext
public override void DrawInContext(CGContext ctx)
{
base.DrawInContext (ctx);
var knobFrame = CGRect.Inflate(Bounds, -2.0f, -2.0f);
UIBezierPath knobPath = UIBezierPath.FromRoundedRect((CGRect)knobFrame, (nfloat)knobFrame.Height / 2.0f);
// 1) fill - with a subtle shadow
ctx.SetShadow(new CGSize(0, 1), 1.0f, UIColor.Gray.CGColor);
ctx.SetFillColor( UIColor.White.CGColor);
ctx.AddPath( knobPath.CGPath);
ctx.FillPath ();
// 2) outline
ctx.SetStrokeColor(UIColor.Gray.CGColor);
ctx.SetLineWidth((nfloat)0.5f);
ctx.AddPath(knobPath.CGPath);
ctx.StrokePath ();
// 3) inner gradient
var rect = CGRect.Inflate(knobFrame, -2.0f, -2.0f);
var clipPath = UIBezierPath.FromRoundedRect ((CGRect)rect, (nfloat)rect.Height / 2.0f);
CGGradient myGradient;
CGColorSpace myColorspace;
nfloat[] locations = { 0.0f, 1.0f };
nfloat[] components = { 0.0f, 0.0f, 0.0f , 0.15f, // Start color
0.0f, 0.0f, 0.0f, 0.05f }; // End color
myColorspace = CGColorSpace.CreateDeviceRGB (); // CGColorSpaceCreateDeviceRGB();
myGradient = new CGGradient( myColorspace, components, locations);
CGPoint startPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMinY());
CGPoint endPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMaxY());
ctx.SaveState ();
ctx.AddPath( clipPath.CGPath);
ctx.Clip ();
ctx.DrawLinearGradient( (CGGradient)myGradient, (CGPoint)startPoint, (CGPoint)endPoint, (CGGradientDrawingOptions)0);
myGradient.Dispose ();
myColorspace.Dispose();
ctx.RestoreState();
// 4) highlight
if (Highlighted)
{
// fill
ctx.SetFillColor(UIColor.FromWhiteAlpha((nfloat)0.0f, (nfloat)0.1f).CGColor);
ctx.AddPath( knobPath.CGPath);
ctx.FillPath();
}
//
// if (Highlighted)
// ctx.SetFillColor (UIColor.Yellow.CGColor);
// else
// ctx.SetFillColor (UIColor.Red.CGColor);
//
// ctx.FillRect (Bounds);
}