简体   繁体   English

Objective-C中的多边形

[英]Polygon in Objective-C

I want to draw polygon as per given in attachment ! 我想按照附件中的说明绘制多边形! Is it possible to do so ? 有可能这样做吗? One more thing about polygon, I want to create it as UIView. 关于多边形的另一件事,我想将其创建为UIView。 Just like as we create rectangle and square. 就像我们创建矩形和正方形一样。 Because I need to use "tag" property. 因为我需要使用“标签”属性。 Is it possible to create polygon in such a way ? 是否可以通过这种方式创建多边形?

I have gone through another idea that I should create three views and attach with eachother (given in attachment ). 我经历了另一个想法,我应该创建三个视图并彼此附加(在附件中给出)。

You can consider some view frames as per example.. 您可以按照示例考虑一些视图框架。

View 1) CGRectMake ( 0,0,50,50); 查看1)CGRectMake(0,0,50,50);

View 2) CGRectMake ( 50,0,50,50); 视图2)CGRectMake(50,0,50,50);

View 3) CGRectMake ( 50,50,50,50); 查看3)CGRectMake(50,50,50,50);

I can create three views but how to concatenate these views and make one view ( Our Polygon )? 我可以创建三个视图,但是如何将这些视图连接起来并制成一个视图( 我们的多边形 )?

Can you give me solution or any advice to implement such problem ? 您能给我解决方案或任何建议来解决此类问题吗?

The entire shape of the UIView will have to be square. UIView的整个形状必须为正方形。 You can't create a UIView that isn't square/rectangular. 您不能创建非正方形/矩形的UIView。

You can draw it using UIBezierPath... 您可以使用UIBezierPath进行绘制...

UIBezierPath *path = [[UIBezierPath alloc] init];

[path moveToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(100, 0)];
[path addLineToPoint:CGPointMake(100, 100)];
... and so on.

Then in drawRect you can... 然后在drawRect中,您可以...

[path stroke];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM