Chintan
Chintan

Reputation: 2808

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. 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);

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

View 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 ?

Upvotes: 0

Views: 1651

Answers (1)

Fogmeister
Fogmeister

Reputation: 77631

The entire shape of the UIView will have to be square. You can't create a UIView that isn't square/rectangular.

You can draw it using 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...

[path stroke];

Upvotes: 3

Related Questions