public override void DrawInContext(CGContext ctx) { UIGraphics.PushContext(ctx); CGRect bounds = this.Bounds; TKFill fill = this.LabelStyle.Fill; TKStroke stroke = new TKStroke(UIColor.Black); TKBalloonShape shape = new TKBalloonShape(TKBalloonShapeArrowPosition.Bottom, new CGSize(bounds.Size.Width - stroke.Width, bounds.Size.Height - stroke.Width)); CGRect textRect; if (this.IsOutsideBounds == true) { shape.ArrowPosition = TKBalloonShapeArrowPosition.Top; textRect = new CGRect(bounds.Left, bounds.Top - this.LabelStyle.Insets.Top + shape.ArrowSize.Height, bounds.Size.Width, bounds.Size.Height + this.LabelStyle.Insets.Bottom); } else { textRect = new CGRect(bounds.Left, bounds.Top - this.LabelStyle.Insets.Top, bounds.Size.Width, bounds.Size.Height + this.LabelStyle.Insets.Bottom); } shape.DrawInContext(ctx, new CGPoint(bounds.GetMidX(), bounds.GetMidY()), new TKDrawing[] { fill, stroke }); NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle(); paragraphStyle.Alignment = this.LabelStyle.TextAlignment; NSDictionary attributes = new NSDictionary(UIStringAttributeKey.Font, UIFont.SystemFontOfSize(18), UIStringAttributeKey.ForegroundColor, this.LabelStyle.TextColor, UIStringAttributeKey.ParagraphStyle, paragraphStyle); NSString text = new NSString(this.Text); text.WeakDrawString(textRect, NSStringDrawingOptions.TruncatesLastVisibleLine | NSStringDrawingOptions.UsesLineFragmentOrigin, attributes, null); UIGraphics.PopContext(); }
public override void DrawInContext (CGContext ctx) { UIGraphics.PushContext (ctx); CGRect bounds = this.Bounds; TKFill fill = this.LabelStyle.Fill; TKStroke stroke = new TKStroke (UIColor.Black); TKBalloonShape shape = new TKBalloonShape (TKBalloonShapeArrowPosition.Bottom ,new CGSize(bounds.Size.Width - stroke.Width, bounds.Size.Height - stroke.Width)); CGRect textRect; if (this.IsOutsideBounds == true) { shape.ArrowPosition = TKBalloonShapeArrowPosition.Top; textRect = new CGRect (bounds.Left, bounds.Top - this.LabelStyle.Insets.Top + shape.ArrowSize.Height, bounds.Size.Width, bounds.Size.Height + this.LabelStyle.Insets.Bottom); } else { textRect = new CGRect (bounds.Left, bounds.Top - this.LabelStyle.Insets.Top, bounds.Size.Width, bounds.Size.Height + this.LabelStyle.Insets.Bottom); } shape.DrawInContext (ctx, new CGPoint (bounds.GetMidX (), bounds.GetMidY ()), new TKDrawing[]{ fill, stroke }); NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle (); paragraphStyle.Alignment = this.LabelStyle.TextAlignment; NSDictionary attributes = new NSDictionary (UIStringAttributeKey.Font, UIFont.SystemFontOfSize (18), UIStringAttributeKey.ForegroundColor, this.LabelStyle.TextColor, UIStringAttributeKey.ParagraphStyle, paragraphStyle); NSString text = new NSString (this.Text); text.WeakDrawString (textRect, NSStringDrawingOptions.TruncatesLastVisibleLine | NSStringDrawingOptions.UsesLineFragmentOrigin, attributes, null); UIGraphics.PopContext (); }
public void DrawingExtensions() { TestRuntime.AssertXcodeVersion(5, 0); using (var s = new NSString("foo")) { NSStringDrawingOptions options = NSStringDrawingOptions.OneShot; var attrib = new UIStringAttributes(); using (var dict = new NSDictionary()) { Assert.DoesNotThrow(() => s.GetBoundingRect(new SizeF(5, 5), options, attrib, null), "GetBoundingRect 1"); Assert.DoesNotThrow(() => s.WeakGetBoundingRect(new SizeF(5, 5), options, dict, null), "WeakGetBoundingRect 1"); Assert.DoesNotThrow(() => s.DrawString(new RectangleF(0, 0, 10, 10), options, attrib, null), "DrawString 1"); Assert.DoesNotThrow(() => s.WeakDrawString(new RectangleF(0, 0, 10, 10), options, dict, null), "WeakDrawString 1"); Assert.DoesNotThrow(() => s.WeakDrawString(new RectangleF(0, 0, 10, 10), dict), "WeakDrawString 2"); Assert.DoesNotThrow(() => s.WeakDrawString(new PointF(0, 0), dict), "WeakDrawString 3"); } } }
public void DrawingExtensions() { if (!TestRuntime.CheckSystemAndSDKVersion(7, 0)) { Assert.Inconclusive("requires iOS7+"); } using (var s = new NSString("foo")) { NSStringDrawingOptions options = NSStringDrawingOptions.OneShot; var attrib = new UIStringAttributes(); using (var dict = new NSDictionary()) { Assert.DoesNotThrow(() => s.GetBoundingRect(new SizeF(5, 5), options, attrib, null), "GetBoundingRect 1"); Assert.DoesNotThrow(() => s.WeakGetBoundingRect(new SizeF(5, 5), options, dict, null), "WeakGetBoundingRect 1"); Assert.DoesNotThrow(() => s.DrawString(new RectangleF(0, 0, 10, 10), options, attrib, null), "DrawString 1"); Assert.DoesNotThrow(() => s.WeakDrawString(new RectangleF(0, 0, 10, 10), options, dict, null), "WeakDrawString 1"); Assert.DoesNotThrow(() => s.WeakDrawString(new RectangleF(0, 0, 10, 10), dict), "WeakDrawString 2"); Assert.DoesNotThrow(() => s.WeakDrawString(new PointF(0, 0), dict), "WeakDrawString 3"); } } }
public void DrawingExtensions() { TestRuntime.AssertXcodeVersion(5, 0); TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 11, throwIfOtherPlatform: false); using (var s = new NSString("foo")) { NSStringDrawingOptions options = NSStringDrawingOptions.OneShot; var attrib = new UIStringAttributes(); using (var dict = new NSDictionary()) { Assert.DoesNotThrow(() => s.GetBoundingRect(new CGSize(5, 5), options, attrib, null), "GetBoundingRect 1"); Assert.DoesNotThrow(() => s.WeakGetBoundingRect(new CGSize(5, 5), options, dict, null), "WeakGetBoundingRect 1"); Assert.DoesNotThrow(() => s.DrawString(new CGRect(0, 0, 10, 10), options, attrib, null), "DrawString 1"); Assert.DoesNotThrow(() => s.WeakDrawString(new CGRect(0, 0, 10, 10), options, dict, null), "WeakDrawString 1"); #if !MONOMAC //WeakDrawString on mac doesn't have versions with these parameters Assert.DoesNotThrow(() => s.WeakDrawString(new CGRect(0, 0, 10, 10), dict), "WeakDrawString 2"); Assert.DoesNotThrow(() => s.WeakDrawString(new CGPoint(0, 0), dict), "WeakDrawString 3"); #endif } } }