- (void) drawTextLink:(NSString *) text inFrame:(CGRect) frameRect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform ctm = CGContextGetCTM(context);
// Translate the origin to the bottom left.
// Notice that 842 is the size of the PDF page.
CGAffineTransformTranslate(ctm, 0.0, 842);
// Flip the handedness of the coordinate system back to right handed.
CGAffineTransformScale(ctm, 1.0, -1.0);
// Convert the update rectangle to the new coordiante system.
CGRect xformRect = CGRectApplyAffineTransform(frameRect, ctm);
NSURL *url = [NSURL URLWithString:text];
UIGraphicsSetPDFContextURLForRect( url, xformRect );
CGContextSaveGState(context);
NSDictionary *attributesDict;
NSMutableAttributedString *attString;
NSNumber *underline = [NSNumber numberWithInt:NSUnderlineStyleSingle];
attributesDict = @{NSUnderlineStyleAttributeName : underline,
NSForegroundColorAttributeName : [UIColor blueColor]};
attString = [[NSMutableAttributedString alloc] initWithString:url.absoluteString attributes:attributesDict];
[attString drawInRect:frameRect];
CGContextRestoreGState(context);
}
Это код, который я нашел, чтобы сделать URL-адреса в PDF кликабельными.
Я все еще изучаю цель-c, поэтому ваша помощь очень ценится.Заранее большое спасибо!
Сейчас я перевёл вот что, и я уверен, что есть пара ошибок:
func drawTextLink(text: NSString, frameRect: CGRect) {
let context: CGContext = UIGraphicsGetCurrentContext()!
var c = context.ctm
let cc = CGAffineTransform.translatedBy(c)
cc.(0.0, 842)
}