当前位置: 首页>>代码示例>>C#>>正文


C# CGContext.SetShadow方法代码示例

本文整理汇总了C#中CGContext.SetShadow方法的典型用法代码示例。如果您正苦于以下问题:C# CGContext.SetShadow方法的具体用法?C# CGContext.SetShadow怎么用?C# CGContext.SetShadow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CGContext的用法示例。


在下文中一共展示了CGContext.SetShadow方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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);
        }
开发者ID:jasallen,项目名称:RangeSliderDemoVideoFiles,代码行数:41,代码来源:RangeSliderTrackLayer.cs

示例2: 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 ();
        }
开发者ID:jasallen,项目名称:FuRangeSlider,代码行数:41,代码来源:FuRangeSliderTrackLayer.cs

示例3: DrawFlag

		protected void DrawFlag (CGContext context)
		{
			// declare vars
			int i, j;
			
			// general sizes
			float flagWidth = imageView.Frame.Width * .8f;
			float flagHeight = (float)(flagWidth / 1.9);
			PointF flagOrigin = new PointF (imageView.Frame.Width * .1f, imageView.Frame.Height / 3);
			
			// stripe
			float stripeHeight = flagHeight / 13;
			float stripeSpacing = stripeHeight * 2;
			RectangleF stripeRect = new RectangleF (0, 0, flagWidth, stripeHeight);
			
			// star field
			float starFieldHeight = 7 * stripeHeight;
			float starFieldWidth = flagWidth * (2f / 5f);
			RectangleF starField = new RectangleF (flagOrigin.X, flagOrigin.Y + (6 * stripeHeight), starFieldWidth, starFieldHeight);
			
			// stars
			float starDiameter = flagHeight * 0.0616f;
			float starHorizontalCenterSpacing = (starFieldWidth / 6);
			float starHorizontalPadding = (starHorizontalCenterSpacing / 4);
			float starVerticalCenterSpacing = (starFieldHeight / 5);
			float starVerticalPadding = (starVerticalCenterSpacing / 4);
			PointF firstStarOrigin = new PointF (flagOrigin.X + starHorizontalPadding, flagOrigin.Y + flagHeight - starVerticalPadding - (starVerticalCenterSpacing / 2));
			PointF secondRowFirstStarOrigin = new PointF (firstStarOrigin.X + (starHorizontalCenterSpacing / 2), firstStarOrigin.Y - (starVerticalCenterSpacing / 2));
			
			// white background + shadow
			context.SaveState ();
			context.SetShadow (new SizeF (15, -15), 7);
			context.SetFillColor (1, 1, 1, 1);
			context.FillRect (new RectangleF (flagOrigin.X, flagOrigin.Y, flagWidth, flagHeight));
			context.RestoreState ();
			
			// create a stripe layer
			using (CGLayer stripeLayer = CGLayer.Create (context, stripeRect.Size)) {
				
				// set red as the fill color
				// this works
				stripeLayer.Context.SetFillColor (1f, 0f, 0f, 1f);
				// but this doesn't ????
				//stripeLayer.Context.SetFillColor (new float[] { 1f, 0f, 0f, 1f });
				// fill the stripe
				stripeLayer.Context.FillRect (stripeRect);
				
				// loop through the stripes and draw the layer
				context.SaveState ();
				for (i = 0; i < 7; i++) {
					Console.WriteLine ("drawing stripe layer");
					// draw the layer
					context.DrawLayer (stripeLayer, flagOrigin);
					// move the origin
					context.TranslateCTM (0, stripeSpacing);
				}
				context.RestoreState ();
			}
			
			// draw the star field
			//BUGBUG: apple bug - this only works on on-screen CGContext and CGLayer
			//context.SetFillColor (new float[] { 0f, 0f, 0.329f, 1.0f });
			context.SetFillColor (0f, 0f, 0.329f, 1.0f);
			context.FillRect (starField);
			
			// create the star layer
			using (CGLayer starLayer = CGLayer.Create (context, starField.Size)) {
				
				// draw the stars
				DrawStar (starLayer.Context, starDiameter);
				
				// 6-star rows
				// save state so that as we translate (move the origin around, 
				// it goes back to normal when we restore)
				context.SaveState ();
				context.TranslateCTM (firstStarOrigin.X, firstStarOrigin.Y);
				// loop through each row
				for (j = 0; j < 5; j++) {
					
					// each star in the row
					for (i = 0; i < 6; i++) {
						
						// draw the star, then move the origin to the right
						context.DrawLayer (starLayer, new PointF (0f, 0f));
						context.TranslateCTM (starHorizontalCenterSpacing, 0f);
					}
					// move the row down, and then back left
					context.TranslateCTM ( (-i * starHorizontalCenterSpacing), -starVerticalCenterSpacing);
				}
				context.RestoreState ();
				
				// 5-star rows			
				context.SaveState ();
				context.TranslateCTM (secondRowFirstStarOrigin.X, secondRowFirstStarOrigin.Y);
				// loop through each row
				for (j = 0; j < 4; j++) {
					
					// each star in the row
					for (i = 0; i < 5; i++) {
						
//.........这里部分代码省略.........
开发者ID:BoogieMAN2K,项目名称:monotouch-samples,代码行数:101,代码来源:Controller.cs

示例4: DrawInContext

		public override void DrawInContext (CGContext context)
		{
			base.DrawInContext (context);

			// Console.WriteLine ("DrawInContext Radius: {0} Thickness: {1} Color: {2}", Radius, Thickness, Color);
			//Console.WriteLine (this.Bounds.Width+"   "+ this.Bounds.Height);

			CGPoint centerPoint = new CGPoint (this.Bounds.Width / 2, this.Bounds.Height / 2);
			CGColor glowColor = new UIColor (Color).ColorWithAlpha (0.85f).CGColor;
			double innerRadius = (Radius - Thickness) > 0 ? Radius - Thickness : 0;

			// Outer circle
			context.AddEllipseInRect (new CGRect (centerPoint.X - (float) Radius,
			                                        centerPoint.Y - (float) Radius,
			                                        (float) Radius * 2,
			                                        (float) Radius * 2));
			// Inner circle
			context.AddEllipseInRect (new CGRect (centerPoint.X - (float) innerRadius,
			                                        centerPoint.Y - (float) innerRadius,
			                                        (float) innerRadius * 2,
			                                        (float) innerRadius * 2));

			// Fill in circle
			context.SetFillColor (Color);
			context.SetShadow (CGSize.Empty, 10.0f, glowColor);
			context.EOFillPath();
		}
开发者ID:Rajneesh360Logica,项目名称:monotouch-samples,代码行数:27,代码来源:AppDelegate.cs

示例5: drawLabel

		void drawLabel (CGContext ctx, CGRect rect, nfloat yCoord, nfloat xCoord, UITextAlignment alignment, string label, bool flipContext = true, bool centerVertical = false)
		{
			// Draw light the sunrise and Sunset labels at the ends of the light box
			using (UIColor fontColor = UIColor.White, shadowColor = UIColor.Black.ColorWithAlpha (0.1f)) {

				var fontAttributes = new UIFontAttributes (new UIFontFeature (CTFontFeatureNumberSpacing.Selector.ProportionalNumbers));

				using (var desc = UIFont.SystemFontOfSize (fontSize).FontDescriptor.CreateWithAttributes (fontAttributes)) {

					using (UIFont font = UIFont.FromDescriptor (desc, fontSize)) {

						// calculating the range of our attributed string
						var range = new NSRange (0, label.Length);

						// set justification for text block
						using (var alignStyle = new NSMutableParagraphStyle { Alignment = alignment }) {

							// add stylistic attributes to out attributed string
							var stringAttributes = new UIStringAttributes {
								ForegroundColor = fontColor,
								Font = font,
								ParagraphStyle = alignStyle
							};

							var target = new CGSize (float.MaxValue, float.MaxValue);

							NSRange fit;

							using (NSMutableAttributedString attrString = new NSMutableAttributedString (label, stringAttributes)) {

								//creating a container for out attributed string 
								using (CTFramesetter framesetter = new CTFramesetter (attrString)) {


									CGSize frameSize = framesetter.SuggestFrameSize (range, null, target, out fit);


									if (alignment == UITextAlignment.Center) xCoord -= (frameSize.Width / 2);

									if (alignment == UITextAlignment.Right) xCoord -= frameSize.Width;


									// subtract the frameSize so the flipped context behaves as expected
									yCoord -= frameSize.Height;

									if (centerVertical) yCoord += (frameSize.Height / 2);


									var textRect = new CGRect (xCoord, yCoord, frameSize.Width, frameSize.Height);

									using (CGPath path = new CGPath ()) {

										path.AddRect (textRect);

										ctx.SetShadow (new CGSize (0.0f, 1.0f), 0.0f, shadowColor.CGColor);

										using (CTFrame frame = framesetter.GetFrame (range, path, null)) {

											if (flipContext) {

												ctx.SaveState ();
												ctx.TranslateCTM (0, rect.Height);
												ctx.ScaleCTM (1, -1);

												frame.Draw (ctx);

												ctx.RestoreState ();

											} else {

												frame.Draw (ctx);
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
开发者ID:colbylwilliams,项目名称:XWeather,代码行数:81,代码来源:DailyGraphView.cs

示例6: 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);
        }
开发者ID:jasallen,项目名称:RangeSliderDemoVideoFiles,代码行数:62,代码来源:RangeSliderKnobLayer.cs


注:本文中的CGContext.SetShadow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。