用点画圆圈

时间:2014-07-10 18:21:38

标签: ios objective-c uiview

我试图让UIView画一个带圆点的圆圈显然我可以让它像这样圆圈

view.layer.cornerRadius = 50.0f;
view.layer.masksToBounds = YES;

但我想提出这样的意见

enter image description here

这一定是可能的,但我无法弄清楚。可能只是累了:/

内容将保存动态图像或更改颜色,因此设计图像是不可能的,因为我需要视图的内容符合形状

1 个答案:

答案 0 :(得分:0)

有很多方法可以实现这一目标。这是一个例子。只需将其放入drawRect:方法。

CGContextRef context = UIGraphicsGetCurrentContext();

// Oval
UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(0, 0, 100, 100)];
[UIColor.grayColor setFill];
[ovalPath fill];

// Rectangle
CGContextSaveGState(context);
CGContextTranslateCTM(context, 79, 50);
CGContextRotateCTM(context, -45 * M_PI / 180);

UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(0, 0, 25, 25)];
[UIColor.grayColor setFill];
[rectanglePath fill];

CGContextRestoreGState(context);

您可能希望获得像PaintCode这样的应用来帮助您处理此类内容。它可以轻松处理这些类型的绘图,并可以帮助您自己学习如何创建它们。

相关问题