【问题标题】:How to draw dots in a semi - circle pattern如何在半圆形图案中绘制点
【发布时间】:2013-08-19 10:21:12
【问题描述】:

如何以编程方式在 iphone 中以半圆形图案绘制点?

【问题讨论】:

标签: iphone ios objective-c drawrect cgcontext


【解决方案1】:

我使用下面的代码

    CGContextRef ctx = UIGraphicsGetCurrentContext();

float angle = 0;

float centerX = self.frame.size.width/2;
float centerY = self.frame.size.width/2;

float startX = 0.0;
float startY = 0.0;
for (int i = 0; i < 8 ; i++) {

    startX = centerX +  cos(angle) * (radius + 50) - 5  ;
    startY = centerY +  sin(angle) * (radius + 50 ) - 5;
    CGContextFillEllipseInRect(ctx, CGRectMake(startX,  startY,  5, 5));
    [[UIColor blackColor] setStroke];
    angle-= M_PI/7;
}

【讨论】:

    【解决方案2】:

    你可以这样 Quartz_2D:-

    - (void)drawRect:(CGRect)rect {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(context, 20.0);
        CGContextSetStrokeColorWithColor(context, 
           [UIColor blueColor].CGColor);
        CGFloat dashArray[] = {2,6,4,2};
        CGContextSetLineDash(context, 3, dashArray, 4);
        CGContextMoveToPoint(context, 10, 200);
        CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200);
        CGContextStrokePath(context);
    }
    

    查看以下所有绘图示例:-

    http://www.techotopia.com/index.php/An_iOS_5_iPhone_Graphics_Drawing_Tutorial_using_Quartz_2D

    【讨论】:

      猜你喜欢
      • 2016-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多