public void AddItem(string identifier, string title) { var layer = new CATextLayer(); layer.String = title; layer.SetFont("SF UI Text Bold"); layer.FontSize = 12; layer.ForegroundColor = NSColor.FromRgb(80, 80, 80).CGColor; layer.ContentsScale = NSScreen.MainScreen.BackingScaleFactor; var attrs = new NSStringAttributes(); attrs.Font = NSFont.FromFontName("SF UI Text Bold", 12); var stringSize = NSStringDrawing.StringSize(layer.String, attrs); var frame = new CGRect(new CGPoint(0, 0), stringSize); layer.Frame = frame; layer.AnchorPoint = new CGPoint(0, 0.5f); items.Add(new BreadcrumbViewItem { Identifier = identifier, Title = title, Layer = layer }); Layer.AddSublayer(layer); NeedsDisplay = true; }
private static CATextLayer CreateCATextLayer(LabelStyle style, string text) { var label = new CATextLayer(); var ctFont = new CoreText.CTFont(style.Font.FontFamily, (float)style.Font.Size); var aString = new Foundation.NSAttributedString(text, new CoreText.CTStringAttributes() { Font = ctFont }); label.SetFont(ctFont); label.FontSize = (float)style.Font.Size; label.ForegroundColor = ToCGColor(style.ForeColor); label.BackgroundColor = TransparentColor; label.ShadowOpacity = 0; label.BorderWidth = 0; label.String = text; var size = GetSizeForText(0, aString); label.Frame = new CGRect(0, 0, size.Width, size.Height); return(label); }
void CreateDbLabelsAndLines() { int value; var scale = Layer.ContentsScale; for (int index = -numDBLines; index <= numDBLines; index++) { value = index * (defaultGain / numDBLines); if (index >= -numDBLines && index <= numDBLines) { var labelLayer = new CATextLayer { String = string.Format("{0} db", value), Name = index.ToString(), FontSize = 14, ContentsScale = scale, ForegroundColor = UIColor.FromWhiteAlpha(0.1f, 1f).CGColor, AlignmentMode = CATextLayer.AlignmentRight }; labelLayer.SetFont(UIFont.SystemFontOfSize(14).Name); dbLabels.Add(labelLayer); containerLayer.AddSublayer(labelLayer); var lineLayer = new CALayer { BackgroundColor = index == 0 ? UIColor.FromWhiteAlpha(0.65f, 1f).CGColor : UIColor.FromWhiteAlpha(0.8f, 1f).CGColor }; dbLines.Add(lineLayer); graphLayer.AddSublayer(lineLayer); } } }
// An AutoResetEvent instance is used for drawing metadata object overlays so that // only one group of metadata object overlays is drawn at a time. MetadataObjectLayer CreateMetadataOverlay(AVMetadataObject metadataObject) { // Transform the metadata object so the bounds are updated to reflect those of the video preview layer. var transformedMetadataObject = PreviewView.VideoPreviewLayer.GetTransformedMetadataObject(metadataObject); // Create the initial metadata object overlay layer that can be used for either machine readable codes or faces. var metadataObjectOverlayLayer = new MetadataObjectLayer { MetadataObject = transformedMetadataObject, LineJoin = CAShapeLayer.JoinRound, LineWidth = 7, StrokeColor = View.TintColor.ColorWithAlpha(0.7f).CGColor, FillColor = View.TintColor.ColorWithAlpha(0.3f).CGColor }; var barcodeMetadataObject = transformedMetadataObject as AVMetadataMachineReadableCodeObject; if (barcodeMetadataObject != null) { var barcodeOverlayPath = BarcodeOverlayPathWithCorners(barcodeMetadataObject.Corners); metadataObjectOverlayLayer.Path = barcodeOverlayPath; // If the metadata object has a string value, display it. if (barcodeMetadataObject.StringValue.Length > 0) { var barcodeOverlayBoundingBox = barcodeOverlayPath.BoundingBox; var font = UIFont.BoldSystemFontOfSize(19).ToCTFont(); var textLayer = new CATextLayer { AlignmentMode = CATextLayer.AlignmentCenter, Bounds = new CGRect(0, 0, barcodeOverlayBoundingBox.Size.Width, barcodeOverlayBoundingBox.Size.Height), ContentsScale = UIScreen.MainScreen.Scale, Position = new CGPoint(barcodeOverlayBoundingBox.GetMidX(), barcodeOverlayBoundingBox.GetMidY()), Wrapped = true, // Invert the effect of transform of the video preview so the text is orientated with the interface orientation. Transform = CATransform3D.MakeFromAffine(PreviewView.Transform).Invert(default(CATransform3D)), AttributedString = new NSAttributedString(barcodeMetadataObject.StringValue, new CTStringAttributes { Font = font, ForegroundColor = UIColor.White.CGColor, StrokeWidth = -5, StrokeColor = UIColor.Black.CGColor }) }; textLayer.SetFont(font); metadataObjectOverlayLayer.AddSublayer(textLayer); } } else if (transformedMetadataObject is AVMetadataFaceObject) { metadataObjectOverlayLayer.Path = CGPath.FromRect(transformedMetadataObject.Bounds); } return(metadataObjectOverlayLayer); }
void CreateFrequencyLabelsAndLines() { float value; bool firstK = true; var scale = Layer.ContentsScale; for (int index = 0; index <= gridLineCount; index++) { value = GetValue((float)index); var labelLayer = new CATextLayer { ForegroundColor = UIColor.FromWhiteAlpha(0.1f, 1f).CGColor, FontSize = 14, AlignmentMode = CATextLayer.AlignmentCenter, ContentsScale = scale, AnchorPoint = CGPoint.Empty }; labelLayer.SetFont(UIFont.SystemFontOfSize(14).Name); frequencyLabels.Add(labelLayer); if (index > 0 && index < gridLineCount) { var lineLayer = new CALayer { BackgroundColor = UIColor.FromWhiteAlpha(0.8f, 1f).CGColor }; freqLines.Add(lineLayer); graphLayer.AddSublayer(lineLayer); var s = GetString(value); if (value >= 1000 && firstK) { s += "K"; firstK = false; } labelLayer.String = s; } else if (index == 0) { labelLayer.String = string.Format("{0} Hz", GetString(value)); } else { labelLayer.String = string.Format("{0} K", GetString(DefaultMaxHertz)); } containerLayer.AddSublayer(labelLayer); } }
public override void Draw(RectangleF rect) { base.Draw(rect); using (var context = UIGraphics.GetCurrentContext()) { UIBezierPath mainAxis = UIBezierPath.FromRoundedRect(new RectangleF(xAxisMargin, 0.0f, 2.0f, rect.Height), 2.0f); UIColor.FromRGB(203, 203, 203).SetFill(); mainAxis.Fill(); float sepInterval = Convert.ToSingle(Math.Floor((rect.Width - xAxisMargin - xTextMargin) / 5)); for (int i = 1; i < 6; i++) { var separatorAxis = new UIBezierPath(); separatorAxis.MoveTo(new PointF(xAxisMargin + sepInterval * i, 0)); separatorAxis.AddLineTo(new PointF(xAxisMargin + sepInterval * i, rect.Height - yAxisMargin)); UIColor.FromRGB(203, 203, 203).SetStroke(); separatorAxis.LineWidth = 1.0f; separatorAxis.SetLineDash(new [] { 1.0f, 1.0f }, 1); separatorAxis.Stroke(); var textLayer = new CATextLayer(); textLayer.ContentsScale = UIScreen.MainScreen.Scale; CGFont font = CGFont.CreateWithFontName(LabelFont.Name); if (font != null) { textLayer.SetFont(font); font.Dispose(); } textLayer.FontSize = LabelFont.PointSize; textLayer.AnchorPoint = new PointF(0.5f, 0.0f); textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.BackgroundColor = UIColor.Clear.CGColor; textLayer.ForegroundColor = LabelColor.CGColor; SizeF size = ((NSString)"0000 h").StringSize(LabelFont); textLayer.String = "00 h"; textLayer.Bounds = new RectangleF(0, 0, size.Width, size.Height); textLayer.Position = new PointF(xAxisMargin + sepInterval * i, rect.Height - yAxisMargin + 5.0f); Layer.AddSublayer(textLayer); xAxisText [i - 1] = textLayer; } } }
private SliceLayer createSliceLayer() { var pieLayer = new SliceLayer(); pieLayer.Frame = _pieView.Frame; var arcLayer = new CAShapeLayer(); arcLayer.ZPosition = 0; arcLayer.StrokeColor = null; pieLayer.AddSublayer(arcLayer); var textLayer = new CATextLayer(); textLayer.ContentsScale = UIScreen.MainScreen.Scale; CGFont font = CGFont.CreateWithFontName(LabelFont.Name); if (font != null) { textLayer.SetFont(font); font.Dispose(); } textLayer.FontSize = LabelFont.PointSize; textLayer.AnchorPoint = new CGPoint(0.5f, 0.5f); textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.BackgroundColor = UIColor.Clear.CGColor; textLayer.ForegroundColor = LabelColor.CGColor; if (LabelShadowColor != null) { textLayer.ShadowColor = LabelShadowColor.CGColor; textLayer.ShadowOffset = CGSize.Empty; textLayer.ShadowOpacity = 1.0f; textLayer.ShadowRadius = 2.0f; } CGSize size = ((NSString)"0").StringSize(LabelFont); textLayer.Frame = new CGRect(new CGPoint(0, 0), size); textLayer.Position = new CGPoint(_pieCenter.X + LabelRadius * (nfloat)Math.Cos(0), _pieCenter.Y + LabelRadius * (nfloat)Math.Sin(0)); pieLayer.AddSublayer(textLayer); layerPool.Add(pieLayer); return(pieLayer); }
public void DidStop(CAAnimation theAnimation, bool finished) { finishedAnimationCount++; if (finishedAnimationCount != animationList.Count) { return; } nfloat nextPos = StartXPos; foreach (var result in Results.OrderByDescending(c => c.ExecutionDate)) { nfloat graphPoint = this.Frame.Height - EndYPos(result.Score); string scoreText = result.Score.ToString(); var scorePath = new CGPath(); scorePath.AddEllipseInRect(new CGRect(new CGPoint(nextPos - ScoreBubleSize.Width / 2, graphPoint), ScoreBubleSize)); var pointLayer = new CAShapeLayer(); pointLayer.Path = scorePath; pointLayer.StrokeColor = graphColor; pointLayer.FillColor = UIColor.Clear.CGColor; this.Layer.AddSublayer(pointLayer); var scoreLayer = new CATextLayer(); scoreLayer.SetFont("System"); scoreLayer.FontSize = 10; scoreLayer.Frame = new CGRect(nextPos - ScoreSize.Width / 2, graphPoint + ScoreBubleSize.Height / 2 - ScoreSize.Height / 2, ScoreSize.Width, ScoreSize.Height); scoreLayer.AlignmentMode = CATextLayer.AlignmentCenter; scoreLayer.String = scoreText; scoreLayer.ForegroundColor = graphColor; this.Layer.AddSublayer(scoreLayer); nextPos -= Offset; } }
CALayer SetupClockFaceLayer() { clockFaceLayer = new CATextLayer() { FontSize = 60, ShadowOpacity = .9f }; clockFaceLayer.Bind("string", clockTimer, "outputString", null); clockFaceLayer.SetFont("Menlo"); // Constrain the text layer in the middle var constraint = CAConstraint.Create(CAConstraintAttribute.MidX, "superlayer", CAConstraintAttribute.MidX); clockFaceLayer.AddConstraint(constraint); constraint = CAConstraint.Create(CAConstraintAttribute.MidY, "superlayer", CAConstraintAttribute.MidY); clockFaceLayer.AddConstraint(constraint); return(clockFaceLayer); }
private static CATextLayer CreateCATextLayer(LabelStyle style, string text) { var label = new CATextLayer (); var ctFont = new CoreText.CTFont (style.Font.FontFamily, (float)style.Font.Size); var aString = new Foundation.NSAttributedString (text, new CoreText.CTStringAttributes() { Font = ctFont }); label.SetFont(ctFont); label.FontSize = (float)style.Font.Size; label.ForegroundColor = ToCGColor(style.ForeColor); label.BackgroundColor = TransparentColor; label.ShadowOpacity = 0; label.BorderWidth = 0; label.String = text; var size = GetSizeForText (0, aString); label.Frame = new CGRect (0, 0, size.Width, size.Height); return label; }
void DrawTextLine(RTRTextLine textLine, CALayer layer, RTRResultStabilityStatus progress) { var topLeft = ScaledPoint(textLine.Quadrangle[0] as NSValue); var bottomLeft = ScaledPoint(textLine.Quadrangle[1] as NSValue); var bottomRight = ScaledPoint(textLine.Quadrangle[2] as NSValue); var topRight = ScaledPoint(textLine.Quadrangle[3] as NSValue); DrawQuadrangle(topLeft, bottomLeft, bottomRight, topRight, layer, progress); var recognizedString = textLine.Text; var textLayer = new CATextLayer(); var textWidth = DistanceBetween(topLeft, topRight); var textHeight = DistanceBetween(topLeft, bottomLeft); var rectForTextLayer = new CGRect(bottomLeft.X, bottomLeft.Y, textWidth, textHeight); // Selecting the initial font size by rectangle var textFont = GetFont(recognizedString, rectForTextLayer); textLayer.SetFont(CGFont.CreateWithFontName(textFont.FontDescriptor.Name)); textLayer.FontSize = textFont.PointSize; textLayer.ForegroundColor = ProgressColor(progress).CGColor; textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.String = recognizedString; textLayer.Frame = rectForTextLayer; // Rotate the text layer var angle = (float)Math.Asin((bottomRight.Y - bottomLeft.Y) / DistanceBetween(bottomLeft, bottomRight)); textLayer.AnchorPoint = new CGPoint(0, 0); textLayer.Position = bottomLeft; //textLayer.Transform = new CATransform3DRotate(CATransform3DIdentity, angle, 0, 0, 1); textLayer.Transform = CATransform3D.MakeRotation(angle, 0, 0, 1); layer.AddSublayer(textLayer); }
CATextLayer SetupTextLayer() { _textLayer = new CATextLayer { ForegroundColor = ProgressPieColors.TextLayerForegroundColor.AsResourceCgColor(), AlignmentMode = CATextLayer.AlignmentCenter, }; _textLayer.SetFont(ProgressPieFonts.TextFont.AsResourceNsFont()); var attrs = new NSMutableDictionary { { NSAttributedString.FontAttributeName, NSFont.FromFontName(ProgressPieFonts.TextFont.AsResourceNsFont().FontName, ProgressPieFonts.TextFont.AsResourceNsFont().PointSize) }, }; var applicationName = new NSAttributedString("100%", attrs); var textSize = applicationName.Size; _textLayer.Frame = new RectangleF(ProgressPieFloats.Radius.AsResourceFloat() - textSize.Width / 2 + ProgressPieFloats.TextLayerMargin.AsFloat(), ProgressPieFloats.Radius.AsResourceFloat() - textSize.Height / 2, textSize.Width, textSize.Height); return(_textLayer); }
void CreateDbLabelsAndLines () { int value; var scale = Layer.ContentsScale; for (int index = -numDBLines; index <= numDBLines; index++) { value = index * (defaultGain / numDBLines); if (index >= -numDBLines && index <= numDBLines) { var labelLayer = new CATextLayer { String = string.Format ("{0} db", value), Name = index.ToString (), FontSize = 14, ContentsScale = scale, ForegroundColor = UIColor.FromWhiteAlpha (0.1f, 1f).CGColor, AlignmentMode = CATextLayer.AlignmentRight }; labelLayer.SetFont (UIFont.SystemFontOfSize (14).Name); dbLabels.Add (labelLayer); containerLayer.AddSublayer (labelLayer); var lineLayer = new CALayer { BackgroundColor = index == 0 ? UIColor.FromWhiteAlpha (0.65f, 1f).CGColor : UIColor.FromWhiteAlpha (0.8f, 1f).CGColor }; dbLines.Add (lineLayer); graphLayer.AddSublayer (lineLayer); } } }
void CreateFrequencyLabelsAndLines () { float value; bool firstK = true; var scale = Layer.ContentsScale; for (int index = 0; index <= gridLineCount; index++) { value = GetValue ((float)index); var labelLayer = new CATextLayer { ForegroundColor = UIColor.FromWhiteAlpha (0.1f, 1f).CGColor, FontSize = 14, AlignmentMode = CATextLayer.AlignmentCenter, ContentsScale = scale, AnchorPoint = CGPoint.Empty }; labelLayer.SetFont (UIFont.SystemFontOfSize (14).Name); frequencyLabels.Add (labelLayer); if (index > 0 && index < gridLineCount) { var lineLayer = new CALayer { BackgroundColor = UIColor.FromWhiteAlpha (0.8f, 1f).CGColor }; freqLines.Add (lineLayer); graphLayer.AddSublayer (lineLayer); var s = GetString (value); if (value >= 1000 && firstK) { s += "K"; firstK = false; } labelLayer.String = s; } else if (index == 0) labelLayer.String = string.Format ("{0} Hz", GetString (value)); else labelLayer.String = string.Format ("{0} K", GetString (DefaultMaxHertz)); containerLayer.AddSublayer (labelLayer); } }
//partial void SelectMetadataObjectTypes(UIButton sender) //{ // var controller = new ItemSelectionViewController<AVMetadataObjectType>(this, // MetadataObjectTypeItemSelectionIdentifier, // this.metadataOutput.AvailableMetadataObjectTypes.GetFlags().ToList(), // this.metadataOutput.MetadataObjectTypes.GetFlags().ToList(), // true); // this.PresentItemSelectionViewController(controller); //} /// <summary> /// 2.스캔결과값 /// </summary> /// <param name="metadataObject"></param> /// <returns></returns> private MetadataObjectLayer CreateMetadataOverlay(AVMetadataObject metadataObject) { // Transform the metadata object so the bounds are updated to reflect those of the video preview layer. var transformedMetadataObject = this.PreviewView.VideoPreviewLayer.GetTransformedMetadataObject(metadataObject); // Create the initial metadata object overlay layer that can be used for either machine readable codes or faces. //빔 컬러 var metadataObjectOverlayLayer = new MetadataObjectLayer { LineWidth = 3, LineJoin = CAShapeLayer.JoinRound, MetadataObject = transformedMetadataObject, FillColor = UIColor.Red.CGColor, StrokeColor = UIColor.Red.CGColor //FillColor = this.View.TintColor.ColorWithAlpha(0.3f).CGColor, //StrokeColor = this.View.TintColor.ColorWithAlpha(0.7f).CGColor }; var barcodeMetadataObject = transformedMetadataObject as AVMetadataMachineReadableCodeObject; if (barcodeMetadataObject != null) { var barcodeOverlayPath = this.BarcodeOverlayPathWithCorners(barcodeMetadataObject.Corners); metadataObjectOverlayLayer.Path = barcodeOverlayPath; // If the metadata object has a string value, display it. string textLayerString = null; //스캔된 바코드 값 //바코드 타입 : barcodeMetadataObject.Type if (!string.IsNullOrEmpty(barcodeMetadataObject.StringValue)) { textLayerString = barcodeMetadataObject.StringValue; } else { // TODO: add Descriptor (line 618 in original iOS sample) } //스캔된 바코드 값 if (!string.IsNullOrEmpty(textLayerString)) { Console.WriteLine("========Result========"); Console.WriteLine(barcodeMetadataObject.Type + ", " + barcodeMetadataObject.StringValue); //this.PreviewView.customOverlay.tableSource.tableItems.Add(new TableItem { Heading = "heading", SubHeading = "subheading", ImageName = "barcode36x36.png" }); //this.InvokeOnMainThread(() => { this.PreviewView.customOverlay.RowAdd("aa", "bb"); }); var barcodeOverlayBoundingBox = barcodeOverlayPath.BoundingBox; var font = UIFont.BoldSystemFontOfSize(16).ToCTFont(); var textLayer = new CATextLayer(); textLayer.TextAlignmentMode = CATextLayerAlignmentMode.Center; //글자표시 박스, 높이가 작아서 글자 안보임 +50추가 textLayer.Bounds = new CGRect(0, 0, barcodeOverlayBoundingBox.Size.Width + 20, barcodeOverlayBoundingBox.Size.Height + 50); //textLayer.Bounds = new CGRect(0, 0, 300, 100); textLayer.ContentsScale = UIScreen.MainScreen.Scale; textLayer.Position = new CGPoint(barcodeOverlayBoundingBox.GetMidX(), barcodeOverlayBoundingBox.GetMidY()); textLayer.Wrapped = true; textLayer.Transform = CATransform3D.MakeFromAffine(this.PreviewView.Transform).Invert(); //------------------------------------- //스캔된 바코드 biz logic //------------------------------------- //연속 스캔 if (this.IsContinue) { if (this.IsFixed) { if (this.AllScanBarcode.Contains(textLayerString)) { //1. 저장 했는지? if (this.SaveCompletedBarcode.Contains(textLayerString)) { //저장 완료 //Color.Green textLayer.String = "저장 완료\n" + textLayerString; textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes { Font = font, StrokeWidth = 0, StrokeColor = UIColor.Black.CGColor, ForegroundColor = UIColor.Green.CGColor }); //경고 audioCautionPlayer.Play(); doubleVibrator.PlaySystemSoundAsync(); } //2. Scan 완료 했는지? else if (this.ScanCompletedBarcode.Contains(textLayerString)) { //스캔 완료 //Color.Yellow textLayer.String = "스캔 완료\n" + textLayerString; textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes { Font = font, StrokeWidth = 0, StrokeColor = UIColor.Black.CGColor, ForegroundColor = UIColor.Yellow.CGColor }); //경고 audioCautionPlayer.Play(); doubleVibrator.PlaySystemSoundAsync(); } else { //------------ //정상처리 작업 //------------ OnScanCompleted?.Invoke(barcodeMetadataObject.Type.ToString(), textLayerString); textLayer.String = textLayerString; textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes { Font = font, StrokeWidth = 0, StrokeColor = UIColor.Black.CGColor, ForegroundColor = UIColor.White.CGColor }); //정상 audioPlayer.Play(); SystemSound.Vibrate.PlaySystemSoundAsync(); if (!this.ScanCompletedBarcode.Contains(textLayerString)) { this.ScanCompletedBarcode.Add(textLayerString); } if (this.AllScanBarcode.Count == this.SaveCompletedBarcode.Count + this.ScanCompletedBarcode.Count) { this.session.StopRunning(); OnScanCompleted?.Invoke(string.Empty, "EXIT"); DismissViewController(true, null); //화면 종료 } else { //연속스캔 사이의 간격 지정 //이 함수 호출하는 부분에서 처리 } } } else { //스캔 대상X //Color.Red textLayer.String = "스캔 대상X\n" + textLayerString; textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes { Font = font, StrokeWidth = 0, StrokeColor = UIColor.Black.CGColor, ForegroundColor = UIColor.Red.CGColor }); //경고 audioCautionPlayer.Play(); doubleVibrator.PlaySystemSoundAsync(); } } //비고정(스캔 대상 없음) else { //현재로서는 biz로직 없음 } } //단일 스캔 else { this.session.StopRunning(); textLayer.String = textLayerString; textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes { Font = font, StrokeWidth = 0, StrokeColor = UIColor.Black.CGColor, ForegroundColor = UIColor.White.CGColor }); //정상 audioPlayer.Play(); SystemSound.Vibrate.PlaySystemSoundAsync(); OnScanCompleted?.Invoke(barcodeMetadataObject.Type.ToString(), textLayerString); DismissViewController(true, null); //화면 종료 } //화면에 표시 textLayer.SetFont(font); metadataObjectOverlayLayer.AddSublayer(textLayer); } } else if (transformedMetadataObject is AVMetadataFaceObject) { metadataObjectOverlayLayer.Path = CGPath.FromRect(transformedMetadataObject.Bounds); } return(metadataObjectOverlayLayer); }
public static void AddBadge(this UIBarButtonItem barButtonItem, string text, UIColor backgroundColor, UIColor textColor, bool filled = true, float fontSize = 11.0f) { if (string.IsNullOrEmpty(text)) { return; } CGPoint offset = CGPoint.Empty; if (backgroundColor == null) { backgroundColor = UIColor.Red; } var font = UIFont.SystemFontOfSize(fontSize); if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { font = UIFont.MonospacedDigitSystemFontOfSize(fontSize, UIFontWeight.Regular); } var view = barButtonItem.ValueForKey(new NSString(@"view")) as UIView; var bLayer = GetBadgeLayer(barButtonItem); bLayer?.RemoveFromSuperLayer(); var badgeSize = text.StringSize(font); var height = badgeSize.Height; var width = badgeSize.Width + 2; /* padding */ //make sure we have at least a circle if (width < height) { width = height; } //x position is offset from right-hand side var x = view.Frame.Width - width + offset.X; var badgeFrame = new CGRect(new CGPoint(x: x, y: offset.Y), size: new CGSize(width: width, height: height)); bLayer = new CAShapeLayer(); DrawRoundedRect(bLayer, badgeFrame, 7.0f, backgroundColor, filled); view.Layer.AddSublayer(bLayer); // Initialiaze Badge's label var label = new CATextLayer { String = text, TextAlignmentMode = CATextLayerAlignmentMode.Center, FontSize = font.PointSize, Frame = badgeFrame, ForegroundColor = filled ? textColor.CGColor : UIColor.White.CGColor, BackgroundColor = UIColor.Clear.CGColor, ContentsScale = UIScreen.MainScreen.Scale }; label.SetFont(CGFont.CreateWithFontName(font.Name)); bLayer.AddSublayer(label); // Save Badge as UIBarButtonItem property objc_setAssociatedObject(barButtonItem.Handle, BadgeKey.Handle, bLayer.Handle, AssociationPolicy.RETAIN_NONATOMIC); }
public override void Draw (CGRect rect) { base.Draw (rect); using (var context = UIGraphics.GetCurrentContext ()) { UIBezierPath mainAxis = UIBezierPath.FromRoundedRect ( new CGRect (xAxisMargin, 0.0f, 2.0f, rect.Height), 2.0f); UIColor.FromRGB ( 203, 203, 203).SetFill(); mainAxis.Fill(); nfloat sepInterval = (nfloat)Math.Floor ((rect.Width - xAxisMargin - xTextMargin)/ 5); for (int i = 1; i < 6; i++) { var separatorAxis = new UIBezierPath(); separatorAxis.MoveTo (new CGPoint (xAxisMargin + sepInterval * i, 0)); separatorAxis.AddLineTo (new CGPoint ( xAxisMargin + sepInterval * i, rect.Height - yAxisMargin)); UIColor.FromRGB ( 203, 203, 203).SetStroke(); separatorAxis.LineWidth = 1.0f; separatorAxis.SetLineDash ( new nfloat[] {1.0f,1.0f}, 1); separatorAxis.Stroke (); var textLayer = new CATextLayer (); textLayer.ContentsScale = UIScreen.MainScreen.Scale; CGFont font = CGFont.CreateWithFontName (LabelFont.Name); if (font != null) { textLayer.SetFont (font); font.Dispose (); } textLayer.FontSize = LabelFont.PointSize; textLayer.AnchorPoint = new CGPoint ( 0.5f, 0.0f); textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.BackgroundColor = UIColor.Clear.CGColor; textLayer.ForegroundColor = LabelColor.CGColor; CGSize size = ((NSString)"0000 h").StringSize (LabelFont); textLayer.String = "00 h"; textLayer.Bounds = new CGRect (0, 0, size.Width, size.Height); textLayer.Position = new CGPoint ( xAxisMargin + sepInterval * i, rect.Height - yAxisMargin + 5.0f); Layer.AddSublayer (textLayer); xAxisText [i - 1] = textLayer; } } }
// An AutoResetEvent instance is used for drawing metadata object overlays so that // only one group of metadata object overlays is drawn at a time. MetadataObjectLayer CreateMetadataOverlay (AVMetadataObject metadataObject) { // Transform the metadata object so the bounds are updated to reflect those of the video preview layer. var transformedMetadataObject = PreviewView.VideoPreviewLayer.GetTransformedMetadataObject (metadataObject); // Create the initial metadata object overlay layer that can be used for either machine readable codes or faces. var metadataObjectOverlayLayer = new MetadataObjectLayer { MetadataObject = transformedMetadataObject, LineJoin = CAShapeLayer.JoinRound, LineWidth = 7, StrokeColor = View.TintColor.ColorWithAlpha (0.7f).CGColor, FillColor = View.TintColor.ColorWithAlpha (0.3f).CGColor }; var barcodeMetadataObject = transformedMetadataObject as AVMetadataMachineReadableCodeObject; if (barcodeMetadataObject != null) { var barcodeOverlayPath = BarcodeOverlayPathWithCorners (barcodeMetadataObject.Corners); metadataObjectOverlayLayer.Path = barcodeOverlayPath; // If the metadata object has a string value, display it. if (barcodeMetadataObject.StringValue.Length > 0) { var barcodeOverlayBoundingBox = barcodeOverlayPath.BoundingBox; var font = UIFont.BoldSystemFontOfSize (19).ToCTFont (); var textLayer = new CATextLayer { AlignmentMode = CATextLayer.AlignmentCenter, Bounds = new CGRect (0, 0, barcodeOverlayBoundingBox.Size.Width, barcodeOverlayBoundingBox.Size.Height), ContentsScale = UIScreen.MainScreen.Scale, Position = new CGPoint (barcodeOverlayBoundingBox.GetMidX (), barcodeOverlayBoundingBox.GetMidY ()), Wrapped = true, // Invert the effect of transform of the video preview so the text is orientated with the interface orientation. Transform = CATransform3D.MakeFromAffine (PreviewView.Transform).Invert (default (CATransform3D)), AttributedString = new NSAttributedString (barcodeMetadataObject.StringValue, new CTStringAttributes { Font = font, ForegroundColor = UIColor.White.CGColor, StrokeWidth = -5, StrokeColor = UIColor.Black.CGColor }) }; textLayer.SetFont (font); metadataObjectOverlayLayer.AddSublayer (textLayer); } } else if (transformedMetadataObject is AVMetadataFaceObject) { metadataObjectOverlayLayer.Path = CGPath.FromRect (transformedMetadataObject.Bounds); } return metadataObjectOverlayLayer; }
/// <summary> /// Initializes a new instance of the <see cref="JZMultiChoice.JZMultiChoicesCircleButton"/> class. /// </summary> /// <param name="point">Center Point.</param> /// <param name="icon">Center Icon</param> /// <param name="sRadius">Small radius.</param> /// <param name="bRadius">Big radius.</param> /// <param name="mMenuItems">Choice items</param> /// <param name="isParallex">If set to <c>true</c> is parallex.</param> /// <param name="parallex">Parallex amount</param> /// <param name="vc">ViewContoller.</param> public JZMultiChoicesCircleButton(CGPoint point, UIImage icon , float sRadius, float bRadius, ChoiceItemCollection mMenuItems, bool isParallex , float parallex, UIViewController vc) : this(UIScreen.MainScreen.Bounds) { this.SmallRadius = sRadius; this.BigRadius = bRadius; this.isTouchDown = false; this.CenterPoint = point; this.IconImage = icon; this.ParallexParameter = parallex; this.Parallex = isParallex; this.ResponderUIVC = vc; BackgroundView = new UIView(new CGRect(point.X - sRadius, point.Y - sRadius, sRadius * 2, sRadius * 2)); BackgroundView.BackgroundColor = new UIColor(0f, 0f, 0f, 0.7f); BackgroundView.Layer.CornerRadius = sRadius; this.Add(BackgroundView); SmallButton = new UIButton(new CGRect(point.X - sRadius, point.Y - sRadius, sRadius * 2, sRadius * 2)); SmallButton.Layer.CornerRadius = sRadius; SmallButton.Layer.BackgroundColor = UIColor.FromRGBA(252.0f / 255.0f, 81.0f / 255.0f, 106.0f / 255.0f, 1.0f).CGColor; SmallButton.Layer.ShadowColor = UIColor.Black.CGColor; SmallButton.Layer.ShadowOffset = new CGSize(0.0f, 6.0f); SmallButton.Layer.ShadowOpacity = 0.3f; SmallButton.Layer.ShadowRadius = 4.0f; SmallButton.Layer.ZPosition = bRadius; SmallButton.SetImage(IconImage, UIControlState.Normal); SmallButton.AddTarget(TouchDown, UIControlEvent.TouchDown); SmallButton.AddTarget(this, new Selector("TouchDrag:withEvent:"), UIControlEvent.TouchDragInside); SmallButton.AddTarget(this, new Selector("TouchDrag:withEvent:"), UIControlEvent.TouchDragOutside); SmallButton.AddTarget(this, new Selector("TouchUpInside:withEvent:"), UIControlEvent.TouchUpInside); SmallButton.AddTarget(TouchUpOutside, UIControlEvent.TouchUpOutside); this.Add(SmallButton); label = new CATextLayer(); label.FontSize = 9.0f; label.String = @"Choose:"; label.FontSize = 40; label.SetFont(@"ArialMT"); label.AlignmentMode = CATextLayer.AlignmentCenter; label.ForegroundColor = UIColor.FromWhiteAlpha(1.0f, 0.0f).CGColor; label.Frame = new CGRect(-SmallRadius * 3, -52, SmallRadius * 8, 100); var UnScaleFactor = SmallRadius / BigRadius; label.Transform = CATransform3D.MakeScale(UnScaleFactor, UnScaleFactor, 1.0f); SmallButton.Layer.AddSublayer(label); var TransformPara = BigRadius / SmallRadius; var MultiChoiceRadius = (BigRadius + SmallRadius) / 8 / TransformPara; this.mItems = mMenuItems; IconArray = new List <UIImageView> (); var number = mMenuItems.Count; foreach (var aItem in this.mItems) { var i = mItems.IndexOf(aItem); var XOffest = 4 * MultiChoiceRadius * Math.Cos(2 * Math.PI * i / number); var YOffest = 4 * MultiChoiceRadius * Math.Sin(2 * Math.PI * i / number); var IconImageView = new UIImageView(new CGRect(sRadius + XOffest - MultiChoiceRadius, sRadius + YOffest - MultiChoiceRadius, MultiChoiceRadius * 2, MultiChoiceRadius * 2)); IconImageView.Image = aItem.Icon; IconImageView.Alpha = 0.0f; IconImageView.Hidden = true; SmallButton.Add(IconImageView); SmallButton.BringSubviewToFront(IconImageView); IconImageView.Layer.ContentsScale = UIScreen.MainScreen.Scale * BigRadius / SmallRadius; IconArray.Add(IconImageView); } var UnFullFactor = SmallRadius / this.Frame.Size.Height; CallbackIcon = new UIImageView(new CGRect((SmallButton.Frame.Size.Width - BigRadius) / 2, (SmallButton.Frame.Size.Height - BigRadius) / 2, BigRadius, BigRadius)); CallbackIcon.Layer.Transform = CATransform3D.MakeScale(UnFullFactor, UnFullFactor, 1.0f); CallbackIcon.Image = UIImage.FromBundle("CallbackSuccess"); CallbackIcon.Alpha = 0.0f; SmallButton.Add(CallbackIcon); CallbackMessage = new UILabel(); CallbackMessage.Text = @""; CallbackMessage.Alpha = 0.0f; CallbackMessage.Font = UIFont.SystemFontOfSize(20.0f); CallbackMessage.Layer.Transform = CATransform3D.MakeScale(UnFullFactor, UnFullFactor, 1.0f); CallbackMessage.TextColor = UIColor.White; //[UIColor whiteColor]; CallbackMessage.TextAlignment = UITextAlignment.Center; CallbackMessage.Frame = new CGRect((SmallButton.Frame.Size.Width - SmallRadius / 2) / 2, (SmallButton.Frame.Size.Height - SmallRadius / 4) / 2 + 6, SmallRadius / 2, SmallRadius / 4); SmallButton.Add(CallbackMessage); // FullPara = this.Frame.Size.Height / SmallRadius; var thning = SmallButton.Layer.ValueForKey(new NSString(@"transform.scale")); if (thning != null) { var val = (NSNumber)NSNumber.FromObject(thning); MidiumPara = val.DoubleValue; } else { MidiumPara = 1.0f; } SmallPara = 1.0f; }
private BarLayer CreateBarLayer ( nfloat barHeight) { var barLayer = new BarLayer () { ZPosition = 0, BorderColor = UIColor.White.CGColor, AnchorPoint = new CGPoint ( 0.0f, 0.5f), Frame = new CGRect ( 0, 0, Bounds.Width, barHeight) }; var mainBar = new CALayer (); mainBar.AnchorPoint = new CGPoint (0.0f, 0.0f); mainBar.Bounds = new CGRect ( 0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight); mainBar.Position = new CGPoint ( xAxisMargin, 0); mainBar.BackgroundColor = MainBarColor.CGColor; mainBar.SetValueForKeyPath ( new NSNumber ( minBarScale), new NSString ( "transform.scale.x")); barLayer.AddSublayer (mainBar); var secondaryBar = new CALayer (); secondaryBar.AnchorPoint = new CGPoint (0.0f, 0.0f); secondaryBar.Bounds = new CGRect ( 0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight); secondaryBar.Position = new CGPoint ( xAxisMargin, 0); secondaryBar.BackgroundColor = SecondaryBarColor.CGColor; secondaryBar.SetValueForKeyPath ( new NSNumber ( minBarScale), new NSString ( "transform.scale.x")); barLayer.AddSublayer (secondaryBar); var emptyBar = new CALayer (); emptyBar.AnchorPoint = new CGPoint (0.0f, 0.0f); emptyBar.Bounds = new CGRect ( 0, 0, 2.0f, barHeight); emptyBar.Position = new CGPoint ( xAxisMargin, 0); emptyBar.BackgroundColor = UIColor.Gray.CGColor; barLayer.AddSublayer (emptyBar); CGFont font = CGFont.CreateWithFontName (LabelFont.Name); CGSize size = ((NSString)"00.00:00").StringSize (LabelFont); var textLayer = new CATextLayer () { ContentsScale = UIScreen.MainScreen.Scale, FontSize = 10.0f, AnchorPoint = new CGPoint (0.0f, 0.5f), AlignmentMode = CATextLayer.AlignmentLeft, BackgroundColor = UIColor.Clear.CGColor, ForegroundColor = LabelColor.CGColor }; barLayer.AddSublayer (textLayer); var timeTextLayer = new CATextLayer () { ContentsScale = UIScreen.MainScreen.Scale, FontSize = 10.0f, AnchorPoint = new CGPoint (0.0f, 0.5f), AlignmentMode = CATextLayer.AlignmentLeft, BackgroundColor = UIColor.Clear.CGColor, ForegroundColor = SecondaryBarColor.CGColor }; barLayer.AddSublayer (timeTextLayer); if (font != null) { textLayer.SetFont (font); timeTextLayer.SetFont (font); font.Dispose (); } CATransaction.DisableActions = true; textLayer.Bounds = new CGRect (new CGPoint (0, 0), size); textLayer.Position = mainBar.Position; timeTextLayer.Bounds = new CGRect (new CGPoint (0, 0), size); timeTextLayer.Position = new CGPoint ( mainBar.Position.X + 5.0f, mainBar.Position.Y); CATransaction.DisableActions = false; return barLayer; }
private BarLayer CreateBarLayer(float barHeight) { var barLayer = new BarLayer() { ZPosition = 0, BorderColor = UIColor.White.CGColor, AnchorPoint = new PointF(0.0f, 0.5f), Frame = new RectangleF(0, 0, Bounds.Width, barHeight) }; var mainBar = new CALayer(); mainBar.AnchorPoint = new PointF(0.0f, 0.0f); mainBar.Bounds = new RectangleF(0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight); mainBar.Position = new PointF(xAxisMargin, 0); mainBar.BackgroundColor = MainBarColor.CGColor; mainBar.SetValueForKeyPath(new NSNumber(minBarScale), new NSString("transform.scale.x")); barLayer.AddSublayer(mainBar); var secondaryBar = new CALayer(); secondaryBar.AnchorPoint = new PointF(0.0f, 0.0f); secondaryBar.Bounds = new RectangleF(0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight); secondaryBar.Position = new PointF(xAxisMargin, 0); secondaryBar.BackgroundColor = SecondaryBarColor.CGColor; secondaryBar.SetValueForKeyPath(new NSNumber(minBarScale), new NSString("transform.scale.x")); barLayer.AddSublayer(secondaryBar); var emptyBar = new CALayer(); emptyBar.AnchorPoint = new PointF(0.0f, 0.0f); emptyBar.Bounds = new RectangleF(0, 0, 2.0f, barHeight); emptyBar.Position = new PointF(xAxisMargin, 0); emptyBar.BackgroundColor = UIColor.Gray.CGColor; barLayer.AddSublayer(emptyBar); CGFont font = CGFont.CreateWithFontName(LabelFont.Name); SizeF size = ((NSString)"00.00:00").StringSize(LabelFont); var textLayer = new CATextLayer() { ContentsScale = UIScreen.MainScreen.Scale, FontSize = 10.0f, AnchorPoint = new PointF(0.0f, 0.5f), AlignmentMode = CATextLayer.AlignmentLeft, BackgroundColor = UIColor.Clear.CGColor, ForegroundColor = LabelColor.CGColor }; barLayer.AddSublayer(textLayer); var timeTextLayer = new CATextLayer() { ContentsScale = UIScreen.MainScreen.Scale, FontSize = 10.0f, AnchorPoint = new PointF(0.0f, 0.5f), AlignmentMode = CATextLayer.AlignmentLeft, BackgroundColor = UIColor.Clear.CGColor, ForegroundColor = SecondaryBarColor.CGColor }; barLayer.AddSublayer(timeTextLayer); if (font != null) { textLayer.SetFont(font); timeTextLayer.SetFont(font); font.Dispose(); } CATransaction.DisableActions = true; textLayer.Bounds = new RectangleF(new PointF(0, 0), size); textLayer.Position = mainBar.Position; timeTextLayer.Bounds = new RectangleF(new PointF(0, 0), size); timeTextLayer.Position = new PointF(mainBar.Position.X + 5.0f, mainBar.Position.Y); CATransaction.DisableActions = false; return(barLayer); }
CALayer SetupClockFaceLayer() { clockFaceLayer = new CATextLayer (){ FontSize = 60, ShadowOpacity = .9f }; clockFaceLayer.Bind ("string", clockTimer, "outputString", null); clockFaceLayer.SetFont ("Menlo-Regular"); // Constrain the text layer in the middle var constraint = CAConstraint.Create (CAConstraintAttribute.MidX, "superlayer", CAConstraintAttribute.MidX); clockFaceLayer.AddConstraint (constraint); constraint = CAConstraint.Create (CAConstraintAttribute.MidY, "superlayer", CAConstraintAttribute.MidY); clockFaceLayer.AddConstraint (constraint); return clockFaceLayer; }
private SliceLayer createSliceLayer () { var pieLayer = new SliceLayer (); pieLayer.Frame = _pieView.Frame; var arcLayer = new CAShapeLayer (); arcLayer.ZPosition = 0; arcLayer.StrokeColor = null; pieLayer.AddSublayer (arcLayer); var textLayer = new CATextLayer (); textLayer.ContentsScale = UIScreen.MainScreen.Scale; CGFont font = CGFont.CreateWithFontName (LabelFont.Name); if (font != null) { textLayer.SetFont (font); font.Dispose (); } textLayer.FontSize = LabelFont.PointSize; textLayer.AnchorPoint = new CGPoint (0.5f, 0.5f); textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.BackgroundColor = UIColor.Clear.CGColor; textLayer.ForegroundColor = LabelColor.CGColor; if (LabelShadowColor != null) { textLayer.ShadowColor = LabelShadowColor.CGColor; textLayer.ShadowOffset = CGSize.Empty; textLayer.ShadowOpacity = 1.0f; textLayer.ShadowRadius = 2.0f; } CGSize size = ((NSString)"0").StringSize (LabelFont); textLayer.Frame = new CGRect (new CGPoint (0, 0), size); textLayer.Position = new CGPoint (_pieCenter.X + LabelRadius * (nfloat)Math.Cos (0), _pieCenter.Y + LabelRadius * (nfloat)Math.Sin (0)); pieLayer.AddSublayer (textLayer); layerPool.Add (pieLayer); return pieLayer; }
public void UpdateLayers() { UIFont textFont = UIFont.SystemFontOfSize(_textLayer.FontSize); nfloat minimumPlane = (float)Math.Min(Frame.Width, Frame.Height); _textLayer.FontSize = Bounds.Height / 2.75f * 0.75f; _textLayer.SetFont(textFont.Name); _textLayer.String = $"{_progressValue * 100}%"; var offset = (Bounds.Height - textFont.LineHeight) / 2; _textLayer.Frame = new CGRect(0, offset, Bounds.Width, Bounds.Height); _textLayer.Hidden = IsIndeterminate || !IsActive; if (IsActive) { _shadowLayer.RemoveAnimation(ANIMATION_SHRINK); _arcLayer.RemoveAnimation(ANIMATION_SHRINK); _shadowLayer.RemoveAnimation(ANIMATION_OPACITYDOWN); _arcLayer.RemoveAnimation(ANIMATION_OPACITYDOWN); if (null == _shadowLayer.AnimationForKey(ANIMATION_GROW)) { // grow arc to full size _pathGrowAnimation.SetFrom(_shadowLayer.Path); _pathGrowAnimation.SetTo(CreateArcPath(minimumPlane)); _shadowLayer.AddAnimation(_pathGrowAnimation, ANIMATION_GROW); _arcLayer.AddAnimation(_pathGrowAnimation, ANIMATION_GROW); _arcLayer.AddAnimation(_pathOpacityUpAnimation, ANIMATION_OPACITYUP); _shadowLayer.AddAnimation(_pathOpacityUpAnimation, ANIMATION_OPACITYDOWN); _pathOpacityDownAnimation.From = NSNumber.FromFloat(_arcLayer.Opacity); _pathOpacityDownAnimation.To = NSNumber.FromFloat(1); } if (IsIndeterminate) { _textLayer.Hidden = true; if (null == _arcLayer.AnimationForKey(ANIMATION_ROTATION)) { SetupRotationAnimation(); _rotationAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn); _arcLayer.AddAnimation(_rotationAnimation, ANIMATION_ROTATION); } if (null == _arcLayer.AnimationForKey(ANIMATION_STROKE)) { SetupStrokeAnimation(); _arcLayer.AddAnimation(_strokeAnimation, ANIMATION_STROKE); } } else { // Don't force a change in the stroke if it's currently being animated. // It will get set to the correct value when the animation completes anyway. if (null == _arcLayer.AnimationForKey(ANIMATION_STROKE)) { _arcLayer.StrokeEnd = ProgressValue; } if (null == _shadowLayer.AnimationForKey(ANIMATION_COLOR)) { _shadowLayer.AddAnimation(_colorAnimation, ANIMATION_COLOR); } } } else { _shadowLayer.RemoveAnimation(ANIMATION_GROW); _arcLayer.RemoveAnimation(ANIMATION_GROW); _shadowLayer.RemoveAnimation(ANIMATION_OPACITYUP); _arcLayer.RemoveAnimation(ANIMATION_OPACITYUP); if (null == _shadowLayer.AnimationForKey(ANIMATION_SHRINK)) { // shrink arc away _pathShrinkAnimation.SetFrom(_shadowLayer.Path); _pathShrinkAnimation.SetTo(CreateArcPath(5)); _pathOpacityDownAnimation.From = NSNumber.FromFloat(_arcLayer.Opacity); _pathOpacityDownAnimation.To = NSNumber.FromFloat(0); _shadowLayer.AddAnimation(_pathShrinkAnimation, ANIMATION_SHRINK); _arcLayer.AddAnimation(_pathShrinkAnimation, ANIMATION_SHRINK); _arcLayer.AddAnimation(_pathOpacityDownAnimation, ANIMATION_OPACITYDOWN); _shadowLayer.AddAnimation(_pathOpacityDownAnimation, ANIMATION_OPACITYDOWN); } } }
public void SetFont(UIFont font) { attributedString.AddAttribute(UIStringAttributeKey.Font, font, new NSRange(0, attributedString.Length)); textLayer.SetFont(font.Name); textLayer.FontSize = font.PointSize; }