IOS 圖形上下文棧

來源:互聯網
上載者:User

標籤:raw   利用   還原   div   oid   儲存繪圖   清空   context   res   

 

- (void)drawRect:(CGRect)rect{            // 擷取上下文    CGContextRef ctx = UIGraphicsGetCurrentContext();    // 儲存一份最純潔的圖形上下文    // 調用一次該方法就會拷貝一個上下文到棧中    CGContextSaveGState(ctx);//CGContextSaveGState(ctx);        // 第一條線    // 利用圖形上下文儲存繪圖資訊    CGContextMoveToPoint(ctx, 150, 20);    CGContextAddLineToPoint(ctx, 20, 100);        // 設定第一條線的狀態    CGContextSetLineWidth(ctx, 10);    CGContextSetLineCap(ctx, kCGLineCapRound);    [[UIColor redColor] set];        // 渲染    CGContextStrokePath(ctx);            // 還原開始儲存的那份最純潔的圖形上下文    CGContextRestoreGState(ctx);        // 第二條線    CGContextMoveToPoint(ctx, 80, 30);    CGContextAddLineToPoint(ctx, 80, 150);    /*    // 清空狀態    CGContextSetLineWidth(ctx, 5);    CGContextSetLineCap(ctx, kCGLineCapButt);    [[UIColor greenColor] set];    */       // 還原開始儲存的那份最純潔的圖形上下文    CGContextRestoreGState(ctx);    /*    // 第3條線    CGContextMoveToPoint(ctx, 200, 30);    CGContextAddLineToPoint(ctx, 80, 150);    */    // 渲染    CGContextStrokePath(ctx);    }

 

IOS 圖形上下文棧

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.