【问题标题】:Xcode making a pdf, trying to round cornersXcode制作pdf,试图圆角
【发布时间】:2014-01-04 19:58:34
【问题描述】:

我正在 iPad 应用程序中制作 pdf。现在我可以制作pdf但是想要添加带有圆角边框的图片。例如,为了在简单视图项的边框上实现我想要的效果,我使用以下代码。

self.SaveButtonProp.layer.cornerRadius=8.0f;
self.SaveButtonProp.layer.masksToBounds=YES;
self.SaveButtonProp.layer.borderColor=[[UIColor blackColor]CGColor];
self.SaveButtonProp.layer.borderWidth= 1.0f;

对于pdf,我使用以下方法将带边框的图片添加到pdf中。

CGContextRef currentContext = UIGraphicsGetCurrentContext();
UIImage * demoImage = [UIImage imageWithData : Image];
UIColor *borderColor = [UIColor blackColor];
CGRect rectFrame = CGRectMake(20, 125, 200, 200);
[demoImage drawInRect:rectFrame];
CGContextSetStrokeColorWithColor(currentContext, borderColor.CGColor);
CGContextSetLineWidth(currentContext, 2);
CGContextStrokeRect(currentContext, rectFrame);

我如何绕过拐角?

谢谢

【问题讨论】:

    标签: objective-c xcode ipad pdf


    【解决方案1】:

    在绘图时,您可以设置剪贴蒙版。例如,创建一个圆角矩形形状的 Bezier 路径并将其作为剪贴蒙版应用到您的图形上下文相对容易。随后绘制的所有内容都将被剪裁。

    如果您想稍后删除剪贴蒙版(例如,因为您有一张带圆角的图像,但其他元素紧随其后),您必须先保存图形状态,然后应用剪贴蒙版并恢复图形状态当你完成圆角时。

    您可以在此处看到非常接近我认为您需要的实际代码: UIImage with rounded corners

    【讨论】:

      【解决方案2】:

      您可以使用一种方法将任何 UIView/UIImageView 转换为 PDF NSData:

      UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
          NSData *data = [self makePDFfromView:imageView];
      

      方法:

      - (NSData *)makePDFfromView:(UIView *)view
      {
          NSMutableData *pdfData = [NSMutableData data];
      
          UIGraphicsBeginPDFContextToData(pdfData, view.bounds, nil);
          UIGraphicsBeginPDFPage();
          CGContextRef pdfContext = UIGraphicsGetCurrentContext();
          [view.layer renderInContext:pdfContext];
          UIGraphicsEndPDFContext();
      
          return pdfData;
      }
      

      也许您可以更改或使用此代码来帮助您解决问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-22
        • 1970-01-01
        • 2015-08-23
        • 1970-01-01
        • 2012-02-14
        • 2019-01-01
        • 2011-11-28
        相关资源
        最近更新 更多