protected override void NativeArrange(CGRect finalRect)
        {
            this.ScrollView.ContentSize = finalRect.Size;

            // That's right. We don't need to rearrange page;
            ////base.NativeArrange(finalRect);
        }
Example #2
0
        public void ShareUrl(object sender, Uri uri)
        {
            var item = new NSUrl(uri.AbsoluteUri);
            var activityItems = new NSObject[] { item };
            UIActivity[] applicationActivities = null;
            var activityController = new UIActivityViewController (activityItems, applicationActivities);

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) 
            {
                var window = UIApplication.SharedApplication.KeyWindow;
                var pop = new UIPopoverController (activityController);

                var barButtonItem = sender as UIBarButtonItem;
                if (barButtonItem != null)
                {
                    pop.PresentFromBarButtonItem(barButtonItem, UIPopoverArrowDirection.Any, true);
                }
                else
                {
                    var rect = new CGRect(window.RootViewController.View.Frame.Width / 2, window.RootViewController.View.Frame.Height / 2, 0, 0);
                    pop.PresentFromRect (rect, window.RootViewController.View, UIPopoverArrowDirection.Any, true);
                }
            } 
            else 
            {
                var viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
                viewController.PresentViewController(activityController, true, null);
            }
        }
		// This sets up a NSOutlineView for demonstration
		internal static NSView SetupOutlineView (CGRect frame)
		{
			// Create our NSOutlineView and set it's frame to a reasonable size. It will be autosized via the NSClipView
			NSOutlineView outlineView = new NSOutlineView () {
				Frame = frame
			};

			// Every NSOutlineView must have at least one column or your Delegate will not be called.
			NSTableColumn column = new NSTableColumn ("Values");
			outlineView.AddColumn (column);
			// You must set OutlineTableColumn or the arrows showing children/expansion will not be drawn
			outlineView.OutlineTableColumn = column;

			// Setup the Delegate/DataSource instances to be interrogated for data and view information
			// In Unified, these take an interface instead of a base class and you can combine these into
			// one instance. 
			outlineView.Delegate = new OutlineViewDelegate ();
			outlineView.DataSource = new OutlineViewDataSource ();

			// NSOutlineView expects to be hosted inside an NSClipView and won't draw correctly otherwise  
			NSClipView clipView = new NSClipView (frame) {
				AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable
			};
			clipView.DocumentView = outlineView;
			return clipView;
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            // Create the chart
            View.BackgroundColor = UIColor.White;
            nfloat margin = UserInterfaceIdiomIsPhone ? 10 : 50;
            CGRect frame = new CGRect (margin, margin, View.Bounds.Width - 2 * margin, View.Bounds.Height - 2 * margin);
            chart = new ShinobiChart (frame) {
                Title = "Apple Stock Price",
                AutoresizingMask = ~UIViewAutoresizing.None,
                LicenseKey = "" // TODO: add your trail licence key here!
            };

            // Add a discountinuous date axis
            chart.XAxis = new SChartDateTimeAxis () {
                Title = "Date",
                EnableGesturePanning = true,
                EnableGestureZooming = true
            };

            chart.YAxis = new SChartNumberAxis () {
                Title = "Price (USD)",
                EnableGesturePanning = true,
                EnableGestureZooming = true
            };

            // Add to the view
            View.AddSubview (chart);

            chart.DataSource = new CandlestickChartDataSource ();
        }
		private void AddBox (string title, CGRect frame, int level, NSColor color)
		{
			var node = Utils.SCBoxNode (title, frame, color, 2.0f, true);
			node.Scale = new SCNVector3 (0.02f, 0.02f, 0.02f);
			node.Position = new SCNVector3 (-5, 1.5f * level, 10);
			ContentNode.AddChildNode (node);
		}
            public override CAAnimation AnimationForSeries(TKChart chart, TKChartSeries series, TKChartSeriesRenderState state, CGRect rect)
            {
                double duration = 0.5;
                List<CAAnimation> animations = new List<CAAnimation> ();

                for (int i = 0; i<(int)state.Points.Count; i++) {
                    string keyPath = string.Format ("seriesRenderStates.{0}.points.{1}.y", series.Index, i);
                    TKChartVisualPoint point = (TKChartVisualPoint)state.Points.ObjectAtIndex((uint)i);
                    double oldY = rect.Height;
                    double half = oldY + (point.Y - oldY)/2.0;
                    CAKeyFrameAnimation a = (CAKeyFrameAnimation)CAKeyFrameAnimation.GetFromKeyPath(keyPath);
                    a.KeyTimes = new NSNumber[] { new NSNumber (0), new NSNumber (0), new NSNumber (1) };
                    a.Values = new NSObject[] { new NSNumber (oldY), new NSNumber (half), new NSNumber (point.Y) };
                    a.Duration = duration;
                    a.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseOut);
                    animations.Add(a);
                }

                CAAnimationGroup group = new CAAnimationGroup ();

                group.Duration = duration;
                group.Animations = animations.ToArray();

                return group;
            }
Example #7
0
		public MyOpenGLView (CGRect frame,NSOpenGLContext context) : base(frame)
		{
			var attribs = new object [] {
				NSOpenGLPixelFormatAttribute.Accelerated,
				NSOpenGLPixelFormatAttribute.NoRecovery,
				NSOpenGLPixelFormatAttribute.DoubleBuffer,
				NSOpenGLPixelFormatAttribute.ColorSize, 24,
				NSOpenGLPixelFormatAttribute.DepthSize, 16 };

			pixelFormat = new NSOpenGLPixelFormat (attribs);

			if (pixelFormat == null)
				Console.WriteLine ("No OpenGL pixel format");

			// NSOpenGLView does not handle context sharing, so we draw to a custom NSView instead
			openGLContext = new NSOpenGLContext (pixelFormat, context);

			openGLContext.MakeCurrentContext ();

			// Synchronize buffer swaps with vertical refresh rate
			openGLContext.SwapInterval = true;

			// Initialize our newly created view.
			InitGL ();

			SetupDisplayLink ();

			// Look for changes in view size
			// Note, -reshape will not be called automatically on size changes because NSView does not export it to override 
			notificationProxy = NSNotificationCenter.DefaultCenter.AddObserver (NSView.GlobalFrameChangedNotification, HandleReshape);
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			// set the background color of the view to white
			View.BackgroundColor = UIColor.White;

			// instantiate a new image view that takes up the whole screen and add it to
			// the view hierarchy
			CGRect imageViewFrame = new CGRect (0, -NavigationController.NavigationBar.Frame.Height, View.Frame.Width, View.Frame.Height);
			imageView = new UIImageView (imageViewFrame);
			View.AddSubview (imageView);

			// create our offscreen bitmap context
			// size
			CGSize bitmapSize = new CGSize (imageView.Frame.Size);
			using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero,
									      (int)bitmapSize.Width, (int)bitmapSize.Height, 8,
									      (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (),
									      CGImageAlphaInfo.PremultipliedFirst)) {

				// draw our coordinates for reference
				DrawCoordinateSpace (context);

				// draw our flag
				DrawFlag (context);

				// add a label
				DrawCenteredTextAtPoint (context, 384, 700, "Stars and Stripes", 60);

				// output the drawing to the view
				imageView.Image = UIImage.FromImage (context.ToImage ());
			}
		}
Example #9
0
        private UIImage CreateImage (NSString title, nfloat scale)
        {
            var titleAttrs = new UIStringAttributes () {
                Font = UIFont.FromName ("HelveticaNeue", 13f),
                ForegroundColor = Color.Gray,
            };

            var titleBounds = new CGRect (
                new CGPoint (0, 0),
                title.GetSizeUsingAttributes (titleAttrs)
            );

            var image = Image.TagBackground;
            var imageBounds = new CGRect (
                0, 0,
                (float)Math.Ceiling (titleBounds.Width) + image.CapInsets.Left + image.CapInsets.Right + 4f,
                (float)Math.Ceiling (titleBounds.Height) + image.CapInsets.Top + image.CapInsets.Bottom
            );

            titleBounds.X = image.CapInsets.Left + 2f;
            titleBounds.Y = image.CapInsets.Top;

            UIGraphics.BeginImageContextWithOptions (imageBounds.Size, false, scale);

            try {
                image.Draw (imageBounds);
                title.DrawString (titleBounds, titleAttrs);
                return UIGraphics.GetImageFromCurrentImageContext ();
            } finally {
                UIGraphics.EndImageContext ();
            }
        }
Example #10
0
		public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
		{
			// Two disjoint rects
			var r1 = new CGRect (50, 50, 10, 10);
			var r2 = new CGRect (100, 100, 10, 10);

			// This condradicts with Apple's doc – https://developer.apple.com/reference/coregraphics/cgrectnull
			// The null rectangle. This is the rectangle returned when, for example, you intersect two disjoint rectangles.
			// Note that the null rectangle is not the same as the zero rectangle. 
			// For example, the union of a rectangle with the null rectangle is the original rectangle (that is, the null rectangle contributes nothing).
			var tmp = r1;
			tmp.Intersect (r2); // this is mutable method
			Console.WriteLine (tmp.IsNull ()); // Expected true, but result is false

			tmp = CGRectIntersection (r1, r2);
			Console.WriteLine (tmp.IsNull ()); // Expected true, actual true

			// This should be CGRectNull
			var rectNull = new CGRect (nfloat.PositiveInfinity, nfloat.PositiveInfinity, 0, 0);
			Console.WriteLine (rectNull.IsNull ());  // Expected true, actual true

			// CGRectEmpty and CGRectNull are different
			var union1 = r1.UnionWith (CGRect.Empty); // new rect {0, 0, 60, 60}
			Console.WriteLine (union1);
			var union2 = r1.UnionWith (rectNull);     // r1
			Console.WriteLine (union2);

			return true;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="GridCollectionView"/> class.
 /// </summary>
 /// <param name="frm">The FRM.</param>
 public GridCollectionView(CGRect frm)
     : base(frm, new UICollectionViewFlowLayout())
 {
     AutoresizingMask = UIViewAutoresizing.All;
     ContentMode = UIViewContentMode.ScaleToFill;
     RegisterClassForCell(typeof(GridViewCell), new NSString (GridViewCell.Key));
 }
Example #12
0
        public TouchDrawView(CGRect rect)
            : base(rect)
        {
            linesInProcess = new Dictionary<string, Line>();
            this.BackgroundColor = UIColor.White;
            this.MultipleTouchEnabled = true;

            UITapGestureRecognizer tapRecognizer = new UITapGestureRecognizer(tap);
            this.AddGestureRecognizer(tapRecognizer);

            UITapGestureRecognizer dbltapRecognizer = new UITapGestureRecognizer(dblTap);
            dbltapRecognizer.NumberOfTapsRequired = 2;
            this.AddGestureRecognizer(dbltapRecognizer);

            UILongPressGestureRecognizer pressRecognizer = new UILongPressGestureRecognizer(longPress);
            this.AddGestureRecognizer(pressRecognizer);

            moveRecognizer = new UIPanGestureRecognizer(moveLine);
            moveRecognizer.WeakDelegate = this;
            moveRecognizer.CancelsTouchesInView = false;
            this.AddGestureRecognizer(moveRecognizer);

            UISwipeGestureRecognizer swipeRecognizer = new UISwipeGestureRecognizer(swipe);
            swipeRecognizer.Direction = UISwipeGestureRecognizerDirection.Up;
            swipeRecognizer.NumberOfTouchesRequired = 3;
            this.AddGestureRecognizer(swipeRecognizer);

            selectedColor = UIColor.Red;
        }
        public override void ViewDidLayoutSubviews()
        {
            base.ViewDidLayoutSubviews ();

            UIView[] subviews = View.Subviews.Where (v => v != NavigationBar).ToArray ();
            var toolBarViews = subviews.Where (v => v is UIToolbar).ToArray ();
            var otherViews = subviews.Where (v => !(v is UIToolbar)).ToArray ();

            nfloat toolbarHeight = 0;

            foreach (var uIView in toolBarViews) {
                uIView.SizeToFit ();
                uIView.Frame = new CGRect {
                    X = 0,
                    Y = View.Bounds.Height - uIView.Frame.Height,
                    Width = View.Bounds.Width,
                    Height = uIView.Frame.Height,
                };
                var thisToolbarHeight = uIView.Frame.Height;
                if (toolbarHeight < thisToolbarHeight) {
                    toolbarHeight = thisToolbarHeight;
                }
            }

            var othersHeight = View.Bounds.Height - toolbarHeight;
            var othersFrame = new CGRect (View.Bounds.X, View.Bounds.Y, View.Bounds.Width, othersHeight);

            foreach (var uIView in otherViews) {
                uIView.Frame = othersFrame;
            }
        }
Example #14
0
        public static BaseItemView Create (CGRect frame, NodeViewController nodeViewController, TreeNode node, string filePath, UIColor kleur)
        {
            var view = BaseItemView.Create(frame, nodeViewController, node, kleur);
            UIWebView webView = new UIWebView();

			string extension = Path.GetExtension (filePath);
			if (extension == ".odt") {
				string viewerPath = NSBundle.MainBundle.PathForResource ("over/viewer/index", "html");

				Uri fromUri = new Uri(viewerPath);
				Uri toUri = new Uri(filePath);
				Uri relativeUri = fromUri.MakeRelativeUri(toUri);
				String relativePath = Uri.UnescapeDataString(relativeUri.ToString());

				NSUrl finalUrl = new NSUrl ("#" + relativePath.Replace(" ", "%20"), new NSUrl(viewerPath, false));
				webView.LoadRequest(new NSUrlRequest(finalUrl));
				webView.ScalesPageToFit = true;
				view.ContentView = webView;

				return view;
			} else {
				NSUrl finalUrl = new NSUrl (filePath, false);
				webView.LoadRequest(new NSUrlRequest(finalUrl));
				webView.ScalesPageToFit = true;
				view.ContentView = webView;

				return view;
			}
		
        }
		/// <summary>
		/// Adds the text.
		/// </summary>
		/// <param name="image">The image.</param>
		/// <param name="text">The text.</param>
		/// <param name="point">The point.</param>
		/// <param name="font">The font.</param>
		/// <param name="color">The color.</param>
		/// <param name="alignment">The alignment.</param>
		/// <returns>UIImage.</returns>
		public static UIImage AddText(
			this UIImage image,
			string text,
			CGPoint point,
			UIFont font,
			UIColor color,
			UITextAlignment alignment = UITextAlignment.Left)
		{
			//var labelRect = new RectangleF(point, new SizeF(image.Size.Width - point.X, image.Size.Height - point.Y));
			var h = text.StringHeight(font, image.Size.Width);
			var labelRect = new CGRect(point, new CGSize(image.Size.Width - point.X, h));

			var label = new UILabel(labelRect)
				            {
					            Font = font,
					            Text = text,
					            TextColor = color,
					            TextAlignment = alignment,
					            BackgroundColor = UIColor.Clear
				            };

			var labelImage = label.ToNativeImage();

			using (var context = image.Size.ToBitmapContext())
			{
				var rect = new CGRect(new CGPoint(0, 0), image.Size);
				context.DrawImage(rect, image.CGImage);
				context.DrawImage(labelRect, labelImage.CGImage);
				context.StrokePath();
				return UIImage.FromImage(context.ToImage());
			}
		}
		void UpdateUI ()
		{
			var x = 44 + 6;

			if (UIDevice.CurrentDevice.CheckSystemVersion (7, 0))
				x += 15; // okay, we need a more thorough iOS 7 update than this, but for now this'll have to do

			var fn = person.FirstNameAndInitials;
			firstNameLabel.Text = fn;
			var fnw = string.IsNullOrEmpty (fn) ? 
				0.0f : 
					UIStringDrawing.StringSize (fn, NormalFont).Width;
			var f = new CGRect (x, 4, fnw + 4, 20);
			firstNameLabel.Frame = f;

			var ln = person.SafeLastName;
			lastNameLabel.Text = ln;
			var lnw = string.IsNullOrEmpty (ln) ?
				0.0f :
					UIStringDrawing.StringSize (ln, BoldFont).Width;
			f.X = f.Right;
			f.Width = lnw;
			lastNameLabel.Frame = f;

			detailsLabel.Text = person.TitleAndDepartment ?? string.Empty;
			detailsLabel.Frame = new CGRect (x, 25, 258, 14);
		}
        public iOSCardsView(CGRect frame)
            : base(frame)
        {
            this.Setup();

            this.Draw(frame);
        }
Example #18
0
		private void Email(string exportType)
        {
            if(!MFMailComposeViewController.CanSendMail)
                return;

            var title = exampleInfo.Title + "." + exportType;
            NSData nsData = null;
            string attachmentType = "text/plain";
            var rect = new CGRect(0,0,800,600);
            switch(exportType)
            {
            case "png":
                nsData =  View.ToPng(rect);
                attachmentType = "image/png";
                break;
            case "pdf":
                nsData = View.ToPdf(rect);
                attachmentType = "text/x-pdf";
                break;
            }

            var mail = new MFMailComposeViewController ();
            mail.SetSubject("OxyPlot - " + title);
            mail.SetMessageBody ("Please find attached " + title, false);
            mail.Finished += HandleMailFinished;
            mail.AddAttachmentData(nsData, attachmentType, title);

            this.PresentViewController (mail, true, null);
        }
Example #19
0
        public override void Draw(CGRect rect)
        {
            var context = UIGraphics.GetCurrentContext();
            var bounds = Bounds;

            UIColor background = Enabled ? pressed ? HighlightedColor : NormalColor : DisabledColor;
            nfloat alpha = 1;

            CGPath container = GraphicsUtil.MakeRoundedRectPath(bounds, 14);
            context.AddPath(container);
            context.Clip();

            using (var cs = CGColorSpace.CreateDeviceRGB())
            {
                var topCenter = new CGPoint(bounds.GetMidX(), 0);
                var midCenter = new CGPoint(bounds.GetMidX(), bounds.GetMidY());
                var bottomCenter = new CGPoint(bounds.GetMidX(), bounds.GetMaxY());

                using (
                    var gradient = new CGGradient(cs, new[] { 0.23f, 0.23f, 0.23f, alpha, 0.47f, 0.47f, 0.47f, alpha },
                                                  new nfloat[] { 0, 1 }))
                {
                    context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }

                container = GraphicsUtil.MakeRoundedRectPath(bounds.Inset(1, 1), 13);
                context.AddPath(container);
                context.Clip();
                using (
                    var gradient = new CGGradient(cs, new[] { 0.05f, 0.05f, 0.05f, alpha, 0.15f, 0.15f, 0.15f, alpha },
                                                  new nfloat[] { 0, 1 }))
                {
                    context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }

                var nb = bounds.Inset(4, 4);
                container = GraphicsUtil.MakeRoundedRectPath(nb, 10);
                context.AddPath(container);
                context.Clip();

                background.SetFill();
                context.FillRect(nb);

                using (var gradient = new CGGradient(cs, new nfloat[] { 1, 1, 1, .35f, 1, 1, 1, 0.06f }, new nfloat[] { 0, 1 }))
                {
                    context.DrawLinearGradient(gradient, topCenter, midCenter, 0);
                }
                context.SetLineWidth(2);
                context.AddPath(container);
                context.ReplacePathWithStrokedPath();
                context.Clip();

                using (
                    var gradient = new CGGradient(cs, new nfloat[] { 1, 1, 1, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f }, new nfloat[] { 0, 1 })
                    )
                {
                    context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }
            }
        }
        public override void DrawRect(CGRect dirtyRect)
        {
            var g = Graphics.FromCurrentContext();

            // NSView does not have a background color so we just use Clear to white here
            g.Clear(Color.White);

            //RectangleF ClientRectangle = this.Bounds;
            CGRect ClientRectangle = dirtyRect;

            // Following codes draw a line from (0, 0) to (1, 1) in unit of inch:
            /*g.PageUnit = GraphicsUnit.Inch;
            Pen blackPen = new Pen(Color.Black, 1/g.DpiX);
            g.DrawLine(blackPen, 0, 0, 1, 1);*/

            // Following code shifts the origin to the center of
            // client area, and then draw a line from (0,0) to (1, 1) inch:
            g.PageUnit = GraphicsUnit.Inch;
            g.TranslateTransform(((float)ClientRectangle.Width / g.DpiX) / 2,
                ((float)ClientRectangle.Height / g.DpiY) / 2);
            Pen greenPen = new Pen(Color.Green, 1 /  g.DpiX);
            g.DrawLine(greenPen, 0, 0, 1, 1);

            g.Dispose ();
        }
 public DrawingView(CGRect rect)
     : base(rect)
 {
     ContentMode = UIViewContentMode.Redraw;
     AutoresizingMask = UIViewAutoresizing.All;
     BackgroundColor = UIColor.White;
 }
Example #22
0
 protected override void NativeArrangeContent(CGRect finalRect)
 {
     if (this.Content is UIElement)
     {
         ((UIElement)this.Content).Arrange(finalRect);
     }
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            // Create the chart
            View.BackgroundColor = UIColor.White;
            nfloat margin = UserInterfaceIdiomIsPhone ? 10 : 50;
            CGRect frame = new CGRect (margin, margin, View.Bounds.Width - 2 * margin, View.Bounds.Height - 2 * margin);
            chart = new ShinobiChart (frame) {
                Title = "Apple Stock Price",
                AutoresizingMask = ~UIViewAutoresizing.None,
                LicenseKey = "", // TODO: add your trail licence key here!

                // add the axes
                XAxis = new SChartDateTimeAxis { Title = "Date" },
                YAxis = new SChartNumberAxis { Title = "Price (USD)" }
            };

            foreach(SChartAxis axis in chart.AllAxes) {
                axis.EnableGesturePanning = true;
                axis.EnableGestureZooming = true;
                axis.EnableMomentumPanning = true;
                axis.EnableMomentumZooming = true;
            }

            View.AddSubview(chart);

            chart.Delegate = new AddingAnnotationsDelegate ();
            chart.DataSource = new AddingAnnotationsDataSource ();
        }
		public override void Draw(CGRect rect)
		{
			base.Draw(rect);

			using (var g = UIGraphics.GetCurrentContext())
			{
				if (image != null)
					g.SetFillColor((UIColor.FromPatternImage(image).CGColor));
				else
					g.SetFillColor(UIColor.LightGray.CGColor);
				g.FillRect(rect);

				if (!initialPoint.IsEmpty)
				{
					g.SetLineWidth(20);
					g.SetBlendMode(CGBlendMode.Clear);
					UIColor.Clear.SetColor();

					if (path.IsEmpty || startNewPath)
					{
						path.AddLines(new CGPoint[] { initialPoint, latestPoint });
						startNewPath = false;
					}
					else
					{
						path.AddLineToPoint(latestPoint);
					}

					g.SetLineCap(CGLineCap.Round);
					g.AddPath(path);		
					g.DrawPath(CGPathDrawingMode.Stroke);
				}
			}
		}
Example #25
0
        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);                
            }
        }
Example #26
0
        public TabControlItem(CGRect frame, string title)
        {
            this.Frame = frame;
            var parentFrame = frame;
            var labelFont = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? UIFont.BoldSystemFontOfSize(15) : UIFont.BoldSystemFontOfSize(10);

            this.labelTitle = new UILabel(new CGRect(0, 0, parentFrame.Width / 2, parentFrame.Height))
            {
                Text = title,
                TextAlignment = UITextAlignment.Center,
                AdjustsFontSizeToFitWidth = true,
                LineBreakMode = UILineBreakMode.TailTruncation,
                Lines = 2,
                Font = labelFont
            };

            this.button = new UIButton(new CGRect(0, 0, parentFrame.Width, parentFrame.Height));
            this.viewColor = new UIView(new CGRect(0, parentFrame.Height - 1, parentFrame.Width, 1));

            this.Add(this.labelTitle);
            this.Add(this.button);
            this.Add(this.viewColor);

            this.button.TouchUpInside += (s, e) =>
            {
                if (tabEnabled)
                {
                    SelectTab();
                }
            };
        }
        public override void LoadView()
        {
			CGRect frame;
            if (ParentViewController != null && ParentViewController.View != null)
            {
				frame = new CGRect(CGPoint.Empty, ParentViewController.View.Frame.Size);
            }
            else
            {
                UIScreen screen = UIScreen.MainScreen;

                // iOS 7 and older reverses width/height in landscape mode when reporting resolution,
                // iOS 8+ reports resolution correctly in all cases
                if (InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight)
                {
					frame = new CGRect(0, 0, (nfloat)Math.Max(screen.Bounds.Width, screen.Bounds.Height), (nfloat)Math.Min(screen.Bounds.Width, screen.Bounds.Height));
                }
                else
                {
					frame = new CGRect(0, 0, screen.Bounds.Width, screen.Bounds.Height);
                }
            }

            base.View = new iOSGameView(_platform, frame);

            // Need to set resize mask to ensure a view resize (which in iOS 8+ corresponds with a rotation) adjusts
            // the view and underlying CALayer correctly
            View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
        }
            public override CAAnimation AnimationForSeries(TKChart chart, TKChartSeries series, TKChartSeriesRenderState state, CGRect rect)
            {
                double duration = 0;
                List<CAAnimation> animations = new List<CAAnimation>();
                for (int i = 0; i<(int)state.Points.Count; i++) {
                    string pointKeyPath = state.AnimationKeyPathForPointAtIndex ((uint)i);

                    string keyPath = string.Format("{0}.distanceFromCenter", pointKeyPath);
                    CAKeyFrameAnimation a = CAKeyFrameAnimation.GetFromKeyPath(keyPath);
                    a.Values = new NSNumber[] { new NSNumber(50), new NSNumber(50), new NSNumber(0) };
                    a.KeyTimes = new NSNumber[] { new NSNumber(0), new NSNumber(i/(i+1.0)), new NSNumber(1) };
                    a.Duration = 0.3 * (i+1.1);
                    animations.Add(a);

                    keyPath = string.Format("{0}.opacity", pointKeyPath);
                    a = CAKeyFrameAnimation.GetFromKeyPath(keyPath);
                    a.Values = new NSNumber[] { new NSNumber(0), new NSNumber(0), new NSNumber(1) };
                    a.KeyTimes = new NSNumber[] { new NSNumber(0), new NSNumber(i/(i+1.0)), new NSNumber(1) };
                    a.Duration = 0.3 * (i+1.1);
                    animations.Add(a);

                    duration = a.Duration;
                }
                CAAnimationGroup g = new CAAnimationGroup();
                g.Duration = duration;
                g.Animations = animations.ToArray();
                return g;
            }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            var inset = this.TextContainerInset;
            var leftInset = inset.Left + this.TextContainer.LineFragmentPadding;
            var rightInset = inset.Left + this.TextContainer.LineFragmentPadding;
            var maxSize = new CGSize()
                {
                    Width = this.Frame.Width - (leftInset + rightInset),
                    Height = this.Frame.Height - (inset.Top + inset.Bottom)
                };
            var size = new NSString(this.Placeholder).StringSize(this.PlaceholderFont, maxSize, UILineBreakMode.WordWrap);
            var frame = new CGRect(new CGPoint(leftInset, inset.Top), size);

            this.placeholderLabel = new UILabel(frame)
                {
                    BackgroundColor = UIColor.Clear,
                    Font = this.PlaceholderFont,
                    LineBreakMode = UILineBreakMode.WordWrap,
                    Lines = 0,
                    Text = this.Placeholder,
                    TextColor = this.PlaceholderColor
                };
            
            this.Add(this.placeholderLabel);
        }
Example #30
0
		public override void Draw (CGRect rect)
		{
			base.Draw (rect);

			if (!initialPoint.IsEmpty) {

				//get graphics context
				using(CGContext g = UIGraphics.GetCurrentContext ()){

					//set up drawing attributes
					g.SetLineWidth (2);
					UIColor.Red.SetStroke ();

					//add lines to the touch points
					if (path.IsEmpty) {
						path.AddLines (new CGPoint[]{initialPoint, latestPoint});
					} else {
						path.AddLineToPoint (latestPoint);
					}

					//use a dashed line
					g.SetLineDash (0, new nfloat[] { 5, 2 * (nfloat)Math.PI });

					//add geometry to graphics context and draw it
					g.AddPath (path);		
					g.DrawPath (CGPathDrawingMode.Stroke);
				}
			}
		}