Create PDF iOS7

前端 未结 3 648
渐次进展
渐次进展 2021-02-04 21:32

to create a pdf programmaticallly inside my iOS app I followed this tutorial on mobile.tut+:

http://mobile.tutsplus.com/tutorials/iphone/generating-pdf-documents/

<
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 22:29

    This is my solution to the PDF Generation issues from recent deprecated methods since IOS7 release:

    - (void)drawDate
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
        CGRect textRect = CGRectMake(160, 120, [[self date]frame].size.width, self.date.frame.size.height);
        NSString *dateString = self.date.text;
        UIFont *font = [UIFont fontWithName:@"Helvetica" size:14];
        NSMutableParagraphStyle *paragraphstyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
        paragraphstyle.lineBreakMode = NSLineBreakByWordWrapping;
        paragraphstyle.alignment = NSTextAlignmentLeft;
        NSDictionary * attributes = @{ NSFontAttributeName:font, NSParagraphStyleAttributeName: paragraphstyle };
        [dateString drawInRect:textRect withAttributes:attributes];
    }
    

    Hope this helps. LMK if you have comments...

提交回复
热议问题