【问题标题】:Drawing cicles on an image view objective c在 imageview 目标 c 上绘制圆圈
【发布时间】:2014-09-02 09:26:09
【问题描述】:

我正在尝试在 ios 应用程序的图像视图上绘制圆圈,会有很多圆圈,我希望它们位于同一层。我的画圆代码是;

UIBezierPath *circle = [UIBezierPath bezierPathWithArcCenter:center
                                                      radius:radius
                                                  startAngle:0
                                                    endAngle:2.0*M_PI
                                                   clockwise:YES];

CAShapeLayer *circleLayer = [CAShapeLayer layer];
circleLayer.bounds = CGRectMake(0, 0, 2.0*radius, 2.0*radius);
circleLayer.path   = circle.CGPath;
circleLayer.backgroundColor = [UIColor orangeColor].CGColor;

我需要一些不同于下面代码的东西;

[imageView.layer addSublayer:circleLayer];

谢谢。

【问题讨论】:

  • 你应该使用UIImagedrawInRect方法。
  • 能给个示例代码吗?我对 Objective C 不太熟悉,谢谢。
  • “我需要一些不同于下面代码的东西”这是什么意思?
  • 这意味着“我需要一些不同于下面代码的东西” [imageView.layer addSublayer:circleLayer];

标签: ios objective-c geometry layer


【解决方案1】:

来自这个网站:http://www.cocoanetics.com/2010/07/drawing-on-uiimages/

- (UIImage *)imageByDrawingCircleOnImage:(UIImage *)image
{
    // begin a graphics context of sufficient size
    UIGraphicsBeginImageContext(image.size);

    // draw original image into the context
    [image drawAtPoint:CGPointZero];

    // get the context for CoreGraphics
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // set stroking color and draw circle
    [[UIColor redColor] setStroke];

    // make circle rect 5 px from border
    CGRect circleRect = CGRectMake(0, 0,
                image.size.width,
                image.size.height);
    circleRect = CGRectInset(circleRect, 5, 5);

    // draw circle
    CGContextStrokeEllipseInRect(ctx, circleRect);

    // make image out of bitmap context
    UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext();

    // free the context
    UIGraphicsEndImageContext();

    return retImage;
}

【讨论】:

  • 谢谢你,我在谷歌上搜索了几个小时。
  • 我认为是时候提高你的谷歌搜索技能了!这是我得到的第三个结果。无论如何,很高兴它有帮助:)
猜你喜欢
  • 2018-10-18
  • 1970-01-01
  • 2015-12-31
  • 2015-10-17
  • 1970-01-01
  • 1970-01-01
  • 2013-12-21
  • 1970-01-01
  • 2018-08-12
相关资源
最近更新 更多