本文整理汇总了C#中CGGradient类的典型用法代码示例。如果您正苦于以下问题:C# CGGradient类的具体用法?C# CGGradient怎么用?C# CGGradient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CGGradient类属于命名空间,在下文中一共展示了CGGradient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
//Generated with PaintCode 2.2
public override void Draw(CGRect rect)
{
base.Draw(rect);
// General Declarations
var colorSpace = CGColorSpace.CreateDeviceRGB();
var context = UIGraphics.GetCurrentContext();
// Color Declarations
var darkBlue = UIColor.FromRGBA(0.053f, 0.123f, 0.198f, 1.000f);
var lightBlue = UIColor.FromRGBA(0.191f, 0.619f, 0.845f, 1.000f);
// Gradient Declarations
var backgroundGradientColors = new CGColor [] {lightBlue.CGColor, darkBlue.CGColor};
var backgroundGradientLocations = new nfloat [] {0.0f, 1.0f};
var backgroundGradient = new CGGradient(colorSpace, backgroundGradientColors, backgroundGradientLocations);
// Rectangle Drawing
var rectangleRect = new CGRect(rect.GetMinX() + (float)Math.Floor(rect.Width * -0.12917f + 0.5f), rect.GetMinY() + (float)Math.Floor(rect.Height * 0.00000f + 0.5f), (float)Math.Floor(rect.Width * 1.00000f + 0.5f) - (float)Math.Floor(rect.Width * -0.12917f + 0.5f), (float)Math.Floor(rect.Height * 1.00000f + 0.5f) - (float)Math.Floor(rect.Height * 0.00000f + 0.5f));
var rectanglePath = UIBezierPath.FromRect(rectangleRect);
context.SaveState();
rectanglePath.AddClip();
context.DrawLinearGradient(backgroundGradient,
new PointF((float)rectangleRect.GetMidX(), (float)rectangleRect.GetMinY()),
new PointF((float)rectangleRect.GetMidX(), (float)rectangleRect.GetMaxY()),
0);
context.RestoreState();
}
示例2: Renderer_Element_SizeChanged
void Renderer_Element_SizeChanged(object sender, EventArgs e)
{
var element = sender as GradientView;
if (element == null)
return;
var bounds = element.Bounds;
var rect = new CGRect(bounds.X, bounds.Y, bounds.Width, bounds.Height);
UIGraphics.BeginImageContext(rect.Size);
using (CGContext g = UIGraphics.GetCurrentContext())
{
using (var rgb = CGColorSpace.CreateDeviceRGB())
{
nfloat[] colors = GetFloatArrayFromColors(element.StartColor, element.EndColor);
var gradient = new CGGradient(rgb, colors, null);
g.DrawRadialGradient(gradient, new CGPoint(0, 0), new nfloat(0), new CGPoint(100, 100), new nfloat(1000), CGGradientDrawingOptions.None);
}
using (var im = UIGraphics.GetImageFromCurrentImageContext())
using (var imageHolder = new UIImageView(im))
Container.AddSubview(imageHolder);
UIGraphics.EndImageContext();
}
}
示例3: MakeBlueSea
public static UIImage MakeBlueSea()
{
UIGraphics.BeginImageContext(new System.Drawing.SizeF(640,1136));
//BEGIN PAINTCODE
//// General Declarations
var colorSpace = CGColorSpace.CreateDeviceRGB();
var context = UIGraphics.GetCurrentContext();
//// Color Declarations
UIColor color = UIColor.FromRGBA(0.114f, 0.705f, 1.000f, 1.000f);
UIColor gradientColor = UIColor.FromRGBA(0.088f, 0.606f, 0.676f, 1.000f);
UIColor gradientColor2 = UIColor.FromRGBA(0.018f, 0.509f, 0.675f, 1.000f);
//// Gradient Declarations
var gradientColors = new CGColor [] {color.CGColor, UIColor.FromRGBA(0.066f, 0.607f, 0.837f, 1.000f).CGColor, gradientColor2.CGColor, gradientColor.CGColor};
var gradientLocations = new float [] {0, 0.21f, 0.46f, 1};
var gradient = new CGGradient(colorSpace, gradientColors, gradientLocations);
//// Rectangle Drawing
var rectanglePath = UIBezierPath.FromRect(new RectangleF(-46.5f, -35.5f, 728, 1192));
context.SaveState();
rectanglePath.AddClip();
context.DrawLinearGradient(gradient, new PointF(317.5f, -35.5f), new PointF(317.5f, 1156.5f), 0);
context.RestoreState();
UIColor.Black.SetStroke();
rectanglePath.LineWidth = 1;
rectanglePath.Stroke();
//END PAINTCODE
var converted = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
return converted;
}
示例4: MessageSummaryView
static MessageSummaryView ()
{
using (var colorspace = CGColorSpace.CreateDeviceRGB ())
{
gradient = new CGGradient (colorspace, new float [] { /* first */ .52f, .69f, .96f, 1, /* second */ .12f, .31f, .67f, 1 }, null); //new float [] { 0, 1 });
}
}
示例5: Draw
public override void Draw(CGRect rect)
{
using (CGContext context = UIGraphics.GetCurrentContext())
{
switch (_Style)
{
case SIAlertViewBackgroundStyle.Gradient:
{
nfloat[] locations = { 0.0f, 1.0f };
nfloat[] colors = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f };
CGGradient gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), colors, locations);
CGPoint center = new CGPoint(Bounds.Size.Width / 2, Bounds.Size.Height / 2);
nfloat radius = (nfloat)Math.Min(Bounds.Size.Width, Bounds.Size.Height);
context.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation);
break;
}
case SIAlertViewBackgroundStyle.Solid:
{
UIColor.FromWhiteAlpha(0f, 0.5f).SetColor();
context.SetFillColor(UIColor.FromWhiteAlpha(0f, 0.5f).CGColor);
context.FillRect(Bounds);
break;
}
}
}
}
示例6: SetUp
private void SetUp()
{
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
gradient = new CGGradient (
colorSpace,
new float[] { 0.95f, 0.95f, 0.95f, 1,
0.85f, 0.85f, 0.85f, 1},
new float[] { 0, 1 });
}
示例7: GradientTheme
public GradientTheme()
{
//BackgroundColor = UIColor.Clear;
TextColor = UIColor.Black;
TextShadowColor = UIColor.LightGray;
TextShadowOffset = new SizeF(1, 0);
gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1 }, new float[] { 0, 1 });
}
示例8: AddImageReflection
public static UIImage AddImageReflection(UIImage image, float reflectionFraction)
{
int reflectionHeight = (int) (image.Size.Height * reflectionFraction);
// Create a 2 bit CGImage containing a gradient that will be used for masking the
// main view content to create the 'fade' of the reflection. The CGImageCreateWithMask
// function will stretch the bitmap image as required, so we can create a 1 pixel wide gradient
// gradient is always black and white and the mask must be in the gray colorspace
var colorSpace = CGColorSpace.CreateDeviceGray ();
// Creat the bitmap context
var gradientBitmapContext = new CGBitmapContext (IntPtr.Zero, 1, reflectionHeight, 8, 0, colorSpace, CGImageAlphaInfo.None);
// define the start and end grayscale values (with the alpha, even though
// our bitmap context doesn't support alpha the gradien requires it)
float [] colors = { 0, 1, 1, 1 };
// Create the CGGradient and then release the gray color space
var grayScaleGradient = new CGGradient (colorSpace, colors, null);
colorSpace.Dispose ();
// create the start and end points for the gradient vector (straight down)
var gradientStartPoint = new PointF (0, reflectionHeight);
var gradientEndPoint = PointF.Empty;
// draw the gradient into the gray bitmap context
gradientBitmapContext.DrawLinearGradient (grayScaleGradient, gradientStartPoint,
gradientEndPoint, CGGradientDrawingOptions.DrawsAfterEndLocation);
grayScaleGradient.Dispose ();
// Add a black fill with 50% opactiy
gradientBitmapContext.SetGrayFillColor (0, 0.5f);
gradientBitmapContext.FillRect (new RectangleF (0, 0, 1, reflectionHeight));
// conver the context into a CGImage and release the context
var gradientImageMask = gradientBitmapContext.ToImage ();
gradientBitmapContext.Dispose ();
// create an image by masking the bitmap of the mainView content with the gradient view
// then release the pre-masked content bitmap and the gradient bitmap
var reflectionImage = image.CGImage.WithMask (gradientImageMask);
gradientImageMask.Dispose ();
var size = new SizeF (image.Size.Width, image.Size.Height + reflectionHeight);
UIGraphics.BeginImageContext (size);
image.Draw (PointF.Empty);
var context = UIGraphics.GetCurrentContext ();
context.DrawImage (new RectangleF (0, image.Size.Height, image.Size.Width, reflectionHeight), reflectionImage);
var result = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
reflectionImage.Dispose ();
return result;
}
示例9: MovieElement
public MovieElement(string caption) : base(UITableViewCellStyle.Default)
{
Caption = caption;
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
gradient = new CGGradient(
colorSpace,
new float[] { 0.95f, 0.95f, 0.95f, 1,
0.85f, 0.85f, 0.85f, 1},
new float[] { 0, 1 } );
}
示例10: HeaderView
static HeaderView()
{
using (var rgb = CGColorSpace.CreateDeviceRGB()){
float [] colorsBottom = {
1, 1, 1, 1f,
0.97f, 0.97f, 0.97f, 1f
};
Gradient = new CGGradient (rgb, colorsBottom, null);
}
}
示例11: DrawInContext
public override void DrawInContext(CoreGraphics.CGContext ctx)
{
base.DrawInContext (ctx);
var knobFrame = CGRect.Inflate(PaintFrame, -2.0f, -2.0f);
UIBezierPath knobPath = UIBezierPath.FromRoundedRect((CGRect)knobFrame, (nfloat)knobFrame.Height * Slider.Curvaceousness / 2.0f);
// 1) fill - with a subtle shadow
ctx.SetShadow(new CGSize(0, 1), 1.0f, UIColor.Gray.CGColor);
ctx.SetFillColor( Slider.KnobColor.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 * Slider.Curvaceousness / 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();
}
}
示例12: GradientTheme
public GradientTheme()
{
//BackgroundColor = UIColor.Clear;
TextColor = UIColor.Black;
TextShadowColor = UIColor.LightGray;
TextShadowOffset = new SizeF(1, 0);
gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1 }, new float[] { 0, 1 });
DrawElementViewAction = (rect, context, cell) => { DrawElementView(rect, context, cell); };
}
示例13: GradientDrawingView
public GradientDrawingView () : base ()
{
using (var rgb = CGColorSpace.CreateDeviceRGB ()) {
nfloat[] colors = {
204f / 255f, 224f / 255f, 244f / 255f, 10f,
29f / 255f, 156f / 255f, 215f / 255f, 10f,
0f / 255f, 50f / 255f, 126f / 255f, 10f,
};
gradient = new CGGradient (rgb, colors, null);
}
}
示例14: DrawContentView
public void DrawContentView(RectangleF rect, CGContext context, UITableViewElementCell cell)
{
context.SaveState();
float r = 0;
float g = 0;
float b = 0;
var gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { r, g, b, 0.20f, r, g, b, 0.40f }, new float[] { 0, 1 });
context.DrawLinearGradient(gradient, new PointF(rect.Left, rect.Top), new PointF(rect.Left, rect.Bottom), CGGradientDrawingOptions.DrawsBeforeStartLocation);
context.RestoreState();
}
示例15: SampleOwnerDrawnElement
public SampleOwnerDrawnElement (string text, DateTime sent, string from) : base(UITableViewCellStyle.Default, "sampleOwnerDrawnElement")
{
this.Subject = text;
this.From = from;
this.Sent = FormatDate(sent);
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
gradient = new CGGradient(
colorSpace,
new float[] { 0.95f, 0.95f, 0.95f, 1,
0.85f, 0.85f, 0.85f, 1},
new float[] { 0, 1 } );
}