Ricerca…


Osservazioni

Il tipo opaco di CGContextRef rappresenta una destinazione di disegno 2D di quarzo. Un contesto grafico contiene parametri di disegno e tutte le informazioni specifiche del dispositivo necessarie per rendere il disegno su una pagina alla destinazione, indipendentemente dal fatto che la destinazione sia una finestra in un'applicazione, un'immagine bitmap, un documento PDF o una stampante.

Disegnare la linea

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineWidth(context, 5.0);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGContextMoveToPoint(context, 200, 400);
CGContextAddLineToPoint(context, 100, 100);
CGContextStrokePath(context);
CGColorSpaceRelease(colorspace);

Linea

Disegna testo

Draw To richiede che il framework Core Text sia aggiunto nella Build Phase

[NSString* textToDraw = @"Welcome to the world Of IOS";
   
    CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
    
    CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL);
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText); 
    CGRect frameRect = CGRectMake(0, 0, 300, 100);
    CGMutablePathRef framePath = CGPathCreateMutable();
    CGPathAddRect(framePath, NULL, frameRect);
    
    CFRange currentRange = CFRangeMake(0, 0);
    CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
    CGPathRelease(framePath); 
    CGContextRef currentContext = UIGraphicsGetCurrentContext();
          
    CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
    CGContextTranslateCTM(currentContext, 200, 300);
    CGContextScaleCTM(currentContext, 2, -2);
    CTFrameDraw(frameRef, currentContext);
    
    CFRelease(frameRef);
    CFRelease(stringRef);
    CFRelease(framesetter);

Testo



Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow