Reputation:
i want to display triangle shape UIView instead of using normal UIView.is it possible?
Upvotes: 5
Views: 4832
Reputation: 17014
A UIView is always a rectangular shape, you can't alter that. However, you could perhaps get the effect you want by using CALayer masking. Make a UIView and apply a custom mask to it, whereby the mask has the appropriate data in it for a triangle. Then any actual content you put in your UIView will only be visible in the appropriate 'triangle' shaped area.
To make your mask layer, you can either use an image (e.g. a png) or use core graphics to draw a triangle.
There's tons of info on this sort of stuff in the Apple Quartz 2D docs.
There's an example here:
http://cocoadev.com/MaskingACALayer
See also this stack overflow question:
There's also info about this stuff in Apple's API docs for UIView and CALayer.
Upvotes: 10