stephen
stephen

Reputation: 1707

size of UIView based on drawRect

so here's the scenario, I would like to add a UIView in the shape of a irregular polygon on top of another UIView. I draw the irregular polygon using the UIView's drawRect method.

I would like to know how to make the frame of the UIView that of the irregular polygon's?

Obiviously i can't use initWithFrame as that would give it a rectangular frame.

Cheers

Upvotes: 1

Views: 620

Answers (1)

Caleb
Caleb

Reputation: 125037

A UIView's frame is a rectangle. From the UIView Class Reference page:

frame

The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.

@property(nonatomic) CGRect frame

So, you're never going to make the view's frame anything other than a CGRect. What you can do, however, is to just use the rectangle as the enclosing rectangle for your polygon. Draw the polygon so that it just fits inside the rectangle, and leave the area outside the polygon transparent.

Upvotes: 2

Related Questions