public override void ViewDidLoad() { base.ViewDidLoad(); this.View.BackgroundColor = UIColor.White; UIUserInterfaceIdiom idiom = UIDevice.CurrentDevice.UserInterfaceIdiom; if (options.Count > 0 || sections.Count > 0) { if (idiom == UIUserInterfaceIdiom.Pad) { this.loadIPadLayout(); } else { this.loadIPhoneLayout(); } } else { if (idiom == UIUserInterfaceIdiom.Pad) { exampleBounds = CGRect.Inflate(this.View.Bounds, -30, -30); } else { exampleBounds = CGRect.Inflate(this.View.Bounds, -10, -10); } } }
void snippet3() { // >> chart-binding-props-cs var chart = new TKChart(CGRect.Inflate(this.View.Bounds, -10, -10)); this.View.AddSubview(chart); chart.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; Random r = new Random(); var dataPoints = new List <CustomObject> (); for (int i = 0; i < 5; i++) { CustomObject obj = new CustomObject() { ObjectID = i, Value1 = r.Next(100), Value2 = r.Next(100), Value3 = r.Next(100) }; dataPoints.Add(obj); } chart.BeginUpdates(); chart.AddSeries(new TKChartLineSeries(dataPoints.ToArray(), "ObjectID", "Value1")); chart.AddSeries(new TKChartAreaSeries(dataPoints.ToArray(), "ObjectID", "Value2")); chart.AddSeries(new TKChartScatterSeries(dataPoints.ToArray(), "ObjectID", "Value3")); chart.EndUpdates(); // << chart-binding-props-cs }
/// <summary> /// Called when the view is first loaded /// </summary> public override void ViewDidLoad() { base.ViewDidLoad(); _panelContainers = new List <PanelContainer>(); _tapToClose = new UITapGestureRecognizer(); _tapToClose.AddTarget(() => HidePanel(CurrentActivePanelContainer)); _slidingGesture = new SlidingGestureRecogniser(_panelContainers, ShouldReceiveTouch, this, View); _slidingGesture.ShowPanel += (sender, e) => ShowPanel(((SlidingGestureEventArgs)e).PanelContainer); _slidingGesture.HidePanel += (sender, e) => HidePanel(((SlidingGestureEventArgs)e).PanelContainer); View.ClipsToBounds = true; View.Layer.ShadowColor = ShadowColor; View.Layer.MasksToBounds = false; View.Layer.ShadowOpacity = ShadowOpacity; CGRect shadow = View.Bounds; shadow.Inflate(new CGSize(3, 3)); View.Layer.ShadowPath = UIBezierPath.FromRoundedRect(shadow, 0).CGPath; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Initialization var cosmos = new CosmosView() { Frame = CGRect.Inflate(this.View.Frame, -10, -10), AutoresizingMask = UIViewAutoresizing.FlexibleDimensions, BackgroundColor = UIColor.LightGray, }; // Settings cosmos.Settings().FillMode = FillMode.Precise; cosmos.Settings().UpdateOnTouch = true; cosmos.Settings().EmptyBorderColor = UIColor.DarkGray; cosmos.Settings().EmptyBorderWidth = 2; cosmos.Settings().FilledColor = UIColor.Purple; cosmos.Settings().FilledBorderColor = UIColor.Purple; cosmos.Settings().StarSize = 50; cosmos.Settings().StarMargin = 8; // Events cosmos.DidFinishTouchingCosmos += (v) => { cosmos.Text = v.ToString(); }; this.View.AddSubview(cosmos); // Perform any additional setup after loading the view, typically from a nib. }
public override void DrawRect(CGRect dirtyRect) { base.DrawRect(dirtyRect); var rectFactory = CreateRectFactory(CornerRadius); if (!IsHidden(FillColor)) { FillColor.SetFill(); rectFactory(Bounds).Fill(); } if (LineThickness > 0 && !IsHidden(StrokeColor)) { StrokeColor.SetStroke(); var halfLineThickness = LineThickness * 0.5f; var path = rectFactory(CGRect.Inflate(Bounds, -halfLineThickness, -halfLineThickness)); path.LineWidth = LineThickness; if (LineDash.Length > 0) // The API doesn't expect an empty line dash array (for some reason) { path.SetLineDash(LineDash.Select(w => w * LineThickness).ToArray(), 0); } path.Stroke(); } }
public void setupCollectionView() { // >> datasource-collectionview-ui-cs var layout = new UICollectionViewFlowLayout(); layout.ItemSize = new CGSize(140, 140); CGRect rect = this.View.Bounds; rect.Inflate(0, -30); var collectionView = new UICollectionView(rect, layout); collectionView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; collectionView.DataSource = this.dataSource; collectionView.BackgroundColor = UIColor.White; this.View.AddSubview(collectionView); // << datasource-collectionview-ui-cs // >> datasource-collectionview-cell-init-cs this.dataSource.Settings.CollectionView.InitCell((UICollectionView collection, NSIndexPath indexPath, UICollectionViewCell cell, NSObject item) => { var tkCell = cell as TKCollectionViewCell; tkCell.Label.Text = this.dataSource.TextFromItem(item, null); tkCell.BackgroundColor = UIColor.Yellow; }); // << datasource-collectionview-cell-init-cs }
void DrawImageBorder(CGContext gc, CGRect rectangle, CGColor strokeColor) { gc.SetLineWidth(1); gc.SetStrokeColor(strokeColor); rectangle.Inflate(-0.5, -0.5); gc.StrokeRect(rectangle); }
public void MoveFromIndex(int fromIndex, int toIndex, nfloat progressPercentage, PagerScroll pagerScroll) { selectedIndex = progressPercentage > 0.5 ? toIndex : fromIndex; CGRect fromFrame = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(fromIndex, 0)).Frame; var numberOfItems = DataSource.GetItemsCount(this, 0); CGRect toFrame; if (toIndex < 0 || toIndex > numberOfItems - 1) { if (toIndex < 0) { var cellAtts = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(0, 0)); toFrame = CGRect.Inflate(cellAtts.Frame, -cellAtts.Frame.Size.Width, 0); } else { var cellAtts = GetLayoutAttributesForItem(NSIndexPath.FromItemSection((numberOfItems - 1), 0)); toFrame = CGRect.Inflate(cellAtts.Frame, cellAtts.Frame.Size.Width, 0); } } else { toFrame = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(toIndex, 0)).Frame; } CGRect targetFrame = fromFrame; if (this.SelectedBarWidth.HasValue) { targetFrame.Size = new CGSize(this.SelectedBarWidth.Value, SelectedBar.Frame.Size.Height); targetFrame.X = fromFrame.X + (fromFrame.Width - this.SelectedBarWidth.Value) / 2; targetFrame.X += (toFrame.X + (toFrame.Width - this.SelectedBarWidth.Value) / 2 - targetFrame.X) * progressPercentage; } else { var targetWidth = targetFrame.Size.Width + (toFrame.Size.Width - fromFrame.Size.Width) * progressPercentage; targetFrame.Size = new CGSize(targetWidth, SelectedBar.Frame.Size.Height); targetFrame.X += (toFrame.X - fromFrame.X) * progressPercentage; } SelectedBar.Frame = new CGRect(targetFrame.X, SelectedBar.Frame.Y, targetFrame.Size.Width, SelectedBar.Frame.Size.Height); nfloat targetContentOffset = 0.0f; if (ContentSize.Width > Frame.Size.Width) { var toContentOffset = ContentOffsetForCell(toFrame, toIndex); var fromContentOffset = ContentOffsetForCell(fromFrame, fromIndex); targetContentOffset = fromContentOffset + ((toContentOffset - fromContentOffset) * progressPercentage); } var animated = Math.Abs(ContentOffset.X - targetContentOffset) > 30 || (fromIndex == toIndex); SetContentOffset(new CGPoint(targetContentOffset, 0), animated: animated); }
public override void Draw(CGRect rect) { UIImage img; UIColor color; if (!Active) { color = UIColor.FromRGBA(0.576f, 0.608f, 0.647f, 1f); img = Images.dateCell; } else if (Today && Selected) { color = UIColor.White; img = Images.todayselected; } else if (Today) { color = UIColor.White; img = Images.today; } else if (Selected) { color = UIColor.White; img = Images.datecellselected; } else { //color = UIColor.DarkTextColor; color = UIColor.FromRGBA(0.275f, 0.341f, 0.412f, 1f); img = Images.dateCell; } //img.Draw (new CGPoint (0, 0)); img.Draw(rect); color.SetColor(); var s1 = new NSString(Text); s1.DrawString(CGRect.Inflate(Bounds, 4, -8), UIFont.BoldSystemFontOfSize(22), UILineBreakMode.WordWrap, UITextAlignment.Center); if (Marked) { var context = UIGraphics.GetCurrentContext(); if (Selected || Today) { context.SetFillColor(1, 1, 1, 1); } else if (!Active) { UIColor.LightGray.SetColor(); } else { context.SetFillColor(75 / 255f, 92 / 255f, 111 / 255f, 1); } context.SetLineWidth(0); context.AddEllipseInRect(new CGRect(Frame.Size.Width / 2 - 2, 45 - 10, 4, 4)); context.FillPath(); } }
public override void Draw(CGRect rect) { UIImage img; UIColor color; if (!Active || !Available) { color = UIColor.FromRGBA(0.576f, 0.608f, 0.647f, 1f); img = Tools.iOSTool.EmbeddedImage("datecell.png"); } else if (Today && Selected) { color = UIColor.White; img = Tools.iOSTool.EmbeddedImage("todayselected.png"); } else if (Today) { color = UIColor.White; img = Tools.iOSTool.EmbeddedImage("today.png"); } else if (Selected) { color = UIColor.White; img = Tools.iOSTool.EmbeddedImage("datecellselected.png"); } else if (Marked) { color = UIColor.White; img = Tools.iOSTool.EmbeddedImage("datecellmarked.png"); } else { //color = UIColor.DarkTextColor; color = (UIColor)(UIColor.FromRGBA(0.275f, 0.341f, 0.412f, 1f)); img = Tools.iOSTool.EmbeddedImage("datecell.png"); } img.Draw(new CGPoint(0, 0)); color.SetColor(); UIKit.UIStringDrawing.DrawString(Text, CGRect.Inflate(Bounds, 4, -8), (UIFont)(UIFont.BoldSystemFontOfSize(22)), UILineBreakMode.WordWrap, UITextAlignment.Center); // if (Marked) // { // var context = UIGraphics.GetCurrentContext(); // if (Selected || Today) // context.SetRGBFillColor(1, 1, 1, 1); // else if (!Active || !Available) // UIColor.LightGray.SetColor(); // else // context.SetRGBFillColor(75/255f, 92/255f, 111/255f, 1); // context.SetLineWidth(0); // context.AddEllipseInRect(new CGRect(Frame.Size.Width/2 - 2, 45-10, 4, 4)); // context.FillPath(); // // } }
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(); } }
public override void DidFinishLaunching(NSNotification notification) { mainWindowController = new MainWindowController(); mainWindowController.Window.MakeKeyAndOrderFront(this); CGRect bounds = mainWindowController.Window.ContentView.Bounds; bounds.Inflate(-50, -50); //mainWindowController.Window.ContentView.AddSubview(new ChartCanvas(mainWindowController.Window.ContentView.Bounds)); mainWindowController.Window.ContentView.AddSubview(new ChartCanvas(bounds)); }
public override void ViewDidLoad() { base.ViewDidLoad(); var chart = new TKChart(CGRect.Inflate(this.View.Bounds, -10, -10)); this.View.AddSubview(chart); chart.DataSource = new ChartDataSource(); chart.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; }
public void Inflate() { var rect = new CGRect(1, 2, 3, 4); rect.Inflate(5, 6); Assert.AreEqual(-4, (int)rect.X, "x 1"); Assert.AreEqual(-4, (int)rect.Y, "y 1"); Assert.AreEqual(13, (int)rect.Width, "w 1"); Assert.AreEqual(16, (int)rect.Height, "h 1"); rect.Inflate(new CGSize(10, 20)); Assert.AreEqual(-14, (int)rect.X, "x 2"); Assert.AreEqual(-24, (int)rect.Y, "y 2"); Assert.AreEqual(33, (int)rect.Width, "w 2"); Assert.AreEqual(56, (int)rect.Height, "h 2"); rect = CGRect.Inflate(rect, 5, 4); Assert.AreEqual(-19, (int)rect.X, "x 3"); Assert.AreEqual(-28, (int)rect.Y, "y 3"); Assert.AreEqual(43, (int)rect.Width, "w 3"); Assert.AreEqual(64, (int)rect.Height, "h 3"); }
void loadIPhoneLayout() { if (sections.Count == 0 && options.Count == 1) { settingsButton = new UIBarButtonItem(options[0].OptionText, UIBarButtonItemStyle.Plain, optionTouched); } else { settingsButton = new UIBarButtonItem(new UIImage("menu.png"), UIBarButtonItemStyle.Plain, settingsTouched); } this.NavigationItem.RightBarButtonItem = settingsButton; exampleBounds = CGRect.Inflate(this.View.Bounds, -10, -10); }
public ChartCanvas(CGRect rect) : base(rect) { ContentMode = UIViewContentMode.Redraw; AutoresizingMask = UIViewAutoresizing.All; BackColor = Color.Wheat; var panelRect = new CGRect (rect.X,rect.Y,rect.Width,rect.Height-20 / UIScreen.MainScreen.Scale); panelRect.Inflate (-20 / UIScreen.MainScreen.Scale,-20 / UIScreen.MainScreen.Scale); panel1 = new PlotPanel (panelRect); panel1.BackColor = Color.AliceBlue; AddSubview (panel1); panel1.Paint += PlotPanelPaint; }
public ChartCanvas(CGRect rect) : base(rect) { ContentMode = UIViewContentMode.Redraw; AutoresizingMask = UIViewAutoresizing.All; BackColor = Color.Wheat; var panelRect = new CGRect(rect.X, rect.Y, rect.Width, rect.Height - 20 / UIScreen.MainScreen.Scale); panelRect.Inflate(-20 / UIScreen.MainScreen.Scale, -20 / UIScreen.MainScreen.Scale); panel1 = new PlotPanel(panelRect); panel1.BackColor = Color.AliceBlue; AddSubview(panel1); panel1.Paint += PlotPanelPaint; }
public override void ViewDidLoad() { base.ViewDidLoad(); pieChart = new TKChart(); donutChart = new TKChart(); CGRect bounds = this.View.Bounds; pieChart.Frame = CGRect.Inflate(new CGRect(this.ExampleBounds.X, this.ExampleBounds.Y, this.ExampleBounds.Width, this.ExampleBounds.Height / 2), 10, 10); pieChart.AutoresizingMask = ~UIViewAutoresizing.None; pieChart.AllowAnimations = true; pieChart.Legend.Hidden = false; pieChart.Legend.Style.Position = TKChartLegendPosition.Right; this.View.AddSubview(pieChart); donutChart.Frame = CGRect.Inflate(new CGRect(this.ExampleBounds.X, this.ExampleBounds.Y + this.ExampleBounds.Height / 2, this.ExampleBounds.Width, this.ExampleBounds.Height / 2), 10, 10); donutChart.AutoresizingMask = ~UIViewAutoresizing.None; donutChart.AllowAnimations = true; donutChart.Legend.Hidden = false; donutChart.Legend.Style.Position = TKChartLegendPosition.Right; this.View.AddSubview(donutChart); List <TKChartDataPoint> list = new List <TKChartDataPoint> (); list.Add(new TKChartDataPoint(new NSNumber(20), null, "Google")); list.Add(new TKChartDataPoint(new NSNumber(30), null, "Apple")); list.Add(new TKChartDataPoint(new NSNumber(10), null, "Microsoft")); list.Add(new TKChartDataPoint(new NSNumber(5), null, "IBM")); list.Add(new TKChartDataPoint(new NSNumber(8), null, "Oracle")); TKChartPieSeries series = new TKChartPieSeries(list.ToArray()); series.SelectionMode = TKChartSeriesSelectionMode.DataPoint; series.SelectionAngle = -Math.PI / 2.0; series.ExpandRadius = 1.2f; series.LabelDisplayMode = TKChartPieSeriesLabelDisplayMode.Inside; pieChart.AddSeries(series); TKChartDonutSeries donutSeries = new TKChartDonutSeries(list.ToArray()); donutSeries.SelectionMode = TKChartSeriesSelectionMode.DataPoint; donutSeries.InnerRadius = 0.6f; donutSeries.ExpandRadius = 1.1f; donutSeries.LabelDisplayMode = TKChartPieSeriesLabelDisplayMode.Inside; donutChart.AddSeries(donutSeries); }
public void setupTableView() { // >> datasource-tableview-ui-cs NSObject[] array = new NSObject[] { NSObject.FromObject(10), NSObject.FromObject(5), NSObject.FromObject(12), NSObject.FromObject(13), NSObject.FromObject(7), NSObject.FromObject(44) }; this.dataSource = new TKDataSource(array); CGRect rect = this.View.Bounds; rect.Inflate(0, -30); UITableView table = new UITableView(rect); table.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; table.DataSource = this.dataSource; this.View.AddSubview(table); // << datasource-tableview-ui-cs // >> datasource-cell-init-cs this.dataSource.Settings.TableView.InitCell((UITableView tableView, NSIndexPath indexPath, UITableViewCell cell, NSObject item) => { cell.TextLabel.Text = "Item:"; cell.DetailTextLabel.Text = this.dataSource.TextFromItem(item, null); }); // << datasource-cell-init-cs // >> datasource-cell-create-cs this.dataSource.Settings.TableView.CreateCell((UITableView tableView, NSIndexPath indexPath, NSObject item) => { UITableViewCell cell = tableView.DequeueReusableCell("cell"); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Value1, "cell"); } return(cell); }); // << datasource-cell-create-cs // >> datasource-cell-group-cs this.dataSource.Group((NSObject item) => { return(NSObject.FromObject(((NSNumber)item).Int32Value % 2 == 0)); }); // << datasource-cell-group-cs }
public override CGRect TextRectForBounds(CGRect bounds, nint numberOfLines) { var rect = base.TextRectForBounds(bounds, numberOfLines); var insetsWithBorder = ActualInsetsWithBorder(); var rectWithDefaultInsets = CGRect.Inflate(rect, -insetsWithBorder.Width, -insetsWithBorder.Height); // If width is less than height // Adjust the width insets to make it look round if (rectWithDefaultInsets.Width < rectWithDefaultInsets.Height) { insetsWithBorder.Width = (rectWithDefaultInsets.Height - rect.Width) / 2; } var result = CGRect.Inflate(rect, -insetsWithBorder.Width, -insetsWithBorder.Height); return(result); }
// Shared initialization code void Initialize() { this.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; BackColor = Color.Wheat; var panelRect = new CGRect(Frame.X, Frame.Y, Frame.Width, Frame.Height); panelRect.Inflate(-20, -20); panel1 = new PlotPanel(panelRect); panel1.BackColor = Color.AliceBlue; this.AddSubview(panel1); // Subscribing to a paint eventhandler to drawingPanel: panel1.Paint += new PaintEventHandler(PlotPanelPaint); }
public override void Draw(CGRect rect) { var rectInset = CGRect.Inflate(rect, new nfloat(BorderWidth / 2), new nfloat(BorderWidth / 2)); var path = UIBezierPath.FromRoundedRect(rectInset, rect.Height / 2); badgeColor.SetFill(); path.Fill(); if (BorderWidth > 0) { borderColor.SetStroke(); path.LineWidth = new nfloat(BorderWidth); path.Stroke(); } base.Draw(rect); }
void ScanClick(CGRect bounds) { var rect = NSScreen.MainScreen.Frame; rect.Width = this.Bounds.Width; rect.Height = this.Bounds.Height; rect.Y = 0; IntPtr imageRef = CGWindowListCreateImage(rect, CGWindowListOption.OnScreenBelowWindow, (uint)Window.WindowNumber, CGWindowImageOption.Default); var cgImage = new CGImage(imageRef); #if DEBUG //DebugHelperSaveImageToDisk(cgImage, "screen.png"); #endif bounds.Inflate(50, 50); var scanResults = DetectAndDecodeImage(cgImage, bounds); HandleDecodeResults(!string.IsNullOrWhiteSpace(scanResults.output) ? scanResults.bounds : bounds, scanResults.output); }
// << chart-populating-delegate-cs void snippet2() { // >> chart-populating-datapoints-cs var chart = new TKChart(CGRect.Inflate(this.View.Bounds, -10, -10)); this.View.AddSubview(chart); chart.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; var categories = new [] { "Greetings", "Perfecto", "NearBy", "Family Store", "Fresh & Green" }; var values = new [] { 70, 75, 58, 59, 88 }; var dataPoints = new List <TKChartDataPoint> (); for (int i = 0; i < categories.Length; ++i) { dataPoints.Add(new TKChartDataPoint(new NSString(categories [i]), new NSNumber(values [i]))); } chart.AddSeries(new TKChartColumnSeries(dataPoints.ToArray())); // << chart-populating-datapoints-cs }
public void SetDefaultPositionOfCorners() { CGPoint[] point = new CGPoint[4]; CGRect rcBounds; if (image == null) { rcBounds = CGRect.Inflate(this.Bounds, GAP, GAP); } else { rcBounds = WholeImageRectInView(); } point[0] = rcBounds.Location; point[1] = new CGPoint(rcBounds.Location.X + rcBounds.Size.Width, rcBounds.Location.Y); point[2] = new CGPoint(rcBounds.Location.X, rcBounds.Location.Y + rcBounds.Size.Height); point[3] = new CGPoint(rcBounds.Location.X + rcBounds.Size.Width, rcBounds.Location.Y + rcBounds.Size.Height); SetCornersCoordinates(point, false); }
public override void DrawRect(CGRect dirtyRect) { base.DrawRect(dirtyRect); FillColor.SetFill(); NSBezierPath.FromOvalInRect(Bounds).Fill(); if (LineThickness > 0) { StrokeColor.SetStroke(); var halfLineThickness = LineThickness * 0.5f; var path = NSBezierPath.FromOvalInRect(CGRect.Inflate(Bounds, -halfLineThickness, -halfLineThickness)); path.LineWidth = LineThickness; if (LineDash.Length > 0) // The API doesn't expect an empty line dash array (for some reason) { path.SetLineDash(LineDash.Select(w => w * LineThickness).ToArray(), 0); } path.Stroke(); } }
private void setLayerFrames() { _trackLayer.Frame = CGRect.Inflate(Bounds, 0f, Bounds.Height / 3.5f * -1f); _trackLayer.SetNeedsDisplay(); _knobWidth = Bounds.Height; _useableTrackLength = Bounds.Width - _knobWidth; var upperKnobCentre = positionForValue(HighValue); _upperKnobLayer.Frame = new CGRect(0, 0, Bounds.Width, _knobWidth); _upperKnobLayer.PaintFrame = new CGRect(upperKnobCentre - _knobWidth / 2, 0, _knobWidth, _knobWidth); var lowerKnobCentre = positionForValue(LowValue); _lowerKnobLayer.Frame = new CGRect(0, 0, Bounds.Width, _knobWidth); _lowerKnobLayer.PaintFrame = new CGRect(lowerKnobCentre - _knobWidth / 2, 0, _knobWidth, _knobWidth); _upperKnobLayer.SetNeedsDisplay(); _lowerKnobLayer.SetNeedsDisplay(); }
void UpdateLayoutConstraints() { this.exampleBounds = this.View.Bounds; this.UpdateHeaderHeight(); this.exampleBounds.Y += this.headerHeight; this.exampleBounds.Height -= this.headerHeight; if (this.offset > 0) { this.exampleBounds.Y += this.offset; this.exampleBounds.Height -= this.offset; } UIUserInterfaceIdiom idiom = UIDevice.CurrentDevice.UserInterfaceIdiom; if (idiom == UIUserInterfaceIdiom.Pad) { exampleBounds = CGRect.Inflate(this.exampleBounds, -30, -30); } else { exampleBounds = CGRect.Inflate(this.exampleBounds, -10, -10); } }
/// <summary> /// Update cached assets to fit the preheated rect /// </summary> public void UpdateCachedAssets() { var collectionView = _albumView.CollectionView; var preheatRect = CGRect.Inflate(collectionView.Bounds, 0.0f, 0.5f * collectionView.Bounds.Height); var delta = Math.Abs(preheatRect.GetMidY() - _previousPreheatRect.GetMidY()); if (delta > collectionView.Bounds.Height / 3.0) { var rects = ComputeDifferenceBetweenRect(_previousPreheatRect, preheatRect); var addedIndexPaths = GetIndexPathsForRects(collectionView, rects.Item1); var removedIndexPaths = GetIndexPathsForRects(collectionView, rects.Item2); var assetsToStartCaching = AssetsAtIndexPaths(addedIndexPaths); var assetsToStopCaching = AssetsAtIndexPaths(removedIndexPaths); _imageManager?.StartCaching(assetsToStartCaching, _cellSize, PHImageContentMode.AspectFill, null); _imageManager?.StopCaching(assetsToStopCaching, _cellSize, PHImageContentMode.AspectFill, null); _previousPreheatRect = preheatRect; } }
public void setupListView() { // >> datasource-listview-ui-cs CGRect rect = this.View.Bounds; rect.Inflate(0, -30); var listView = new TKListView(rect); listView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; this.dataSource.SetDataSourceFor(listView); this.View.AddSubview(listView); // << datasource-listview-ui-cs // >> datasource-listview-cell-create-cs this.dataSource.Settings.ListView.CreateCell((TKListView list1, NSIndexPath indexPath, NSObject item) => { return(list1.DequeueReusableCell("myCustomCell", indexPath) as TKListViewCell); }); this.dataSource.Settings.ListView.InitCell((TKListView list2, NSIndexPath indexPath, TKListViewCell cell, NSObject item) => { cell.TextLabel.Text = this.dataSource.TextFromItem(item, null); (cell.BackgroundView as TKView).Fill = new TKSolidFill(new UIColor(0.1f, 0.1f, 0.1f, 0.1f)); }); // << datasource-listview-cell-create-cs }
// Shared initialization code void Initialize() { this.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; BackColor = Color.Wheat; var panelRect = new CGRect(Frame.X,Frame.Y,Frame.Width,Frame.Height); panelRect.Inflate(-20,-20); panel1 = new PlotPanel(panelRect); panel1.BackColor = Color.AliceBlue; this.AddSubview (panel1); // Subscribing to a paint eventhandler to drawingPanel: panel1.Paint += new PaintEventHandler (PlotPanelPaint); }
public override void LayoutSubviews() { base.LayoutSubviews(); this.ContentView.Frame = CGRect.Inflate(this.ContentView.Frame, -1, -1); }
public static SCNNode SCBoxNode (string title, CGRect frame, NSColor color, float cornerRadius, bool centered) { NSMutableDictionary titleAttributes = null; NSMutableDictionary centeredTitleAttributes = null; // create and extrude a bezier path to build the box var path = NSBezierPath.FromRoundedRect (frame, cornerRadius, cornerRadius); path.Flatness = 0.05f; var shape = SCNShape.Create (path, 20); shape.ChamferRadius = 0.0f; var node = SCNNode.Create (); node.Geometry = shape; // create an image and fill with the color and text var textureSize = new CGSize (); textureSize.Width = NMath.Ceiling (frame.Size.Width * 1.5f); textureSize.Height = NMath.Ceiling (frame.Size.Height * 1.5f); var texture = new NSImage (textureSize); texture.LockFocus (); var drawFrame = new CGRect (0, 0, textureSize.Width, textureSize.Height); nfloat hue, saturation, brightness, alpha; (color.UsingColorSpace (NSColorSpace.DeviceRGBColorSpace)).GetHsba (out hue, out saturation, out brightness, out alpha); var lightColor = NSColor.FromDeviceHsba (hue, saturation - 0.2f, brightness + 0.3f, alpha); lightColor.Set (); NSGraphics.RectFill (drawFrame); NSBezierPath fillpath = null; if (cornerRadius == 0 && centered == false) { //special case for the "labs" slide drawFrame.Offset (0, -2); fillpath = NSBezierPath.FromRoundedRect (drawFrame, cornerRadius, cornerRadius); } else { drawFrame.Inflate (-3, -3); fillpath = NSBezierPath.FromRoundedRect (drawFrame, cornerRadius, cornerRadius); } color.Set (); fillpath.Fill (); // draw the title if any if (title != null) { if (titleAttributes == null) { var paraphStyle = new NSMutableParagraphStyle (); paraphStyle.LineBreakMode = NSLineBreakMode.ByWordWrapping; paraphStyle.Alignment = NSTextAlignment.Center; paraphStyle.MinimumLineHeight = 38; paraphStyle.MaximumLineHeight = 38; var font = NSFont.FromFontName ("Myriad Set Semibold", 34) != null ? NSFont.FromFontName ("Myriad Set Semibold", 34) : NSFont.FromFontName ("Avenir Medium", 34); var shadow = new NSShadow (); shadow.ShadowOffset = new CGSize (0, -2); shadow.ShadowBlurRadius = 4; shadow.ShadowColor = NSColor.FromDeviceWhite (0.0f, 0.5f); titleAttributes = new NSMutableDictionary (); titleAttributes.SetValueForKey (font, NSAttributedString.FontAttributeName); titleAttributes.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName); titleAttributes.SetValueForKey (shadow, NSAttributedString.ShadowAttributeName); titleAttributes.SetValueForKey (paraphStyle, NSAttributedString.ParagraphStyleAttributeName); var centeredParaphStyle = (NSMutableParagraphStyle)paraphStyle.MutableCopy (); centeredParaphStyle.Alignment = NSTextAlignment.Center; centeredTitleAttributes = new NSMutableDictionary (); centeredTitleAttributes.SetValueForKey (font, NSAttributedString.FontAttributeName); centeredTitleAttributes.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName); centeredTitleAttributes.SetValueForKey (shadow, NSAttributedString.ShadowAttributeName); centeredTitleAttributes.SetValueForKey (paraphStyle, NSAttributedString.ParagraphStyleAttributeName); } var attrString = new NSAttributedString (title, centered ? centeredTitleAttributes : titleAttributes); var textSize = attrString.Size; //check if we need two lines to draw the text var twoLines = title.Contains ("\n"); if (!twoLines) twoLines = textSize.Width > frame.Size.Width && title.Contains (" "); //if so, we need to adjust the size to center vertically if (twoLines) textSize.Height += 38; if (!centered) drawFrame.Inflate (-15, 0); //center vertically var dy = (drawFrame.Size.Height - textSize.Height) * 0.5f; var drawFrameHeight = drawFrame.Size.Height; drawFrame.Size = new CGSize (drawFrame.Size.Width, drawFrame.Size.Height - dy); attrString.DrawString (drawFrame); } texture.UnlockFocus (); //set the created image as the diffuse texture of our 3D box var front = SCNMaterial.Create (); front.Diffuse.Contents = texture; front.LocksAmbientWithDiffuse = true; //use a lighter color for the chamfer and sides var sides = SCNMaterial.Create (); sides.Diffuse.Contents = lightColor; node.Geometry.Materials = new SCNMaterial[] { front, sides, sides, sides, sides }; return node; }