使用CGContextRef中的Transform來輔助作圖

//開始繪畫
    UIGraphicsBeginImageContext(self.view.bounds.size);
    CGContextRef gc = UIGraphicsGetCurrentContext();

    //設(shè)置顏色
    [[UIColor grayColor] setFill];

    //設(shè)置中心點
    CGFloat cenX = CGRectGetMidX(self.view.bounds);
    CGFloat cenY = CGRectGetMidY(self.view.bounds);
    CGContextTranslateCTM(gc, cenX, cenY);



    //不斷繪圖并設(shè)置旋轉(zhuǎn)
    for (int i = 0; i < 12; i ++) {
//        CGContextAddRect(gc, CGRectMake(-5, 0, 10, 100));
        CGContextAddRect(gc, CGRectMake(-5, 50, 10, 50));
//        CGContextAddRect(gc, CGRectMake(-5, 10, 2, 50));

        CGContextFillPath(gc);
        CGContextRotateCTM(gc, 30 * M_PI / 180);
    }

    //結(jié)束繪畫
    UIImage *destImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    //創(chuàng)建UIImageView并顯示在界面上
    UIImageView *imageView = [[UIImageView alloc] initWithImage:destImg];
    [self.view addSubview:imageView];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容