自定义UIPrintPageRenderer不呈现任何内容

时间:2011-08-02 22:59:34

标签: iphone ios mono xamarin.ios

我已经创建了自己的UIPrintPageRenderer子类,并且在DrawContentForPage()的重载中,我绘制了一个简单的矩形,但没有渲染:

public override void DrawContentForPage (int index, RectangleF contentRect)
{
    Context vContext = UIGraphics.GetCurrentContext ();
    vContext.SetStrokeColor (new float[] { 1.0f, 0.0f, 0.0f, 1.0f });
    vContext.SetLineWidth (10);
    vContext.StrokeRect (new RectangleF (PrintableRect.Left + 10, PrintableRect.Top + 10, 100, 100));
}

为什么不呢?

1 个答案:

答案 0 :(得分:0)

事实证明,有两种方法可以“解决”这个问题:

  1. vContext.SetStrokeColor (new float[] { 1.0f, 0.0f, 0.0f, 1.0f });更改为vContext.SetRGBStrokeColor(1.0f, 0.0f, 0.0f, 1.0f);

  2. 致电vContext.SetStrokeColorSpace (CGColorSpace.CreateDeviceRGB ());

  3. 这两种解决方案都具有在设置颜色值之前首先将当前笔划颜色空间设置为RGB的效果。之前没有工作的原因是因为颜色空间显然没有设置为RGB(可能是CMYK或其他东西)。

相关问题