I need to create a UIView that has the left border inclined with 45 degrees I was wondering,is there a way to acheive this programmatically? Does CATransform3D help me in this case since it’s not really a “3D rotation”?
Edit
Here's an image explaining more my needed output
If you just want the shape with no content then you can create a
CAShapeLayer
and add it to your view's layer. (In fact you can also put content in there using this method but you'll need to alter it a bit).This doesn't require using
drawRect
or anything. You will have to change the coordinates based on the values you want.You can also use a
UIView
subclass and overridedrawRect
. It requires more work but theUIBezierPath
will be pretty much the same.CALayer
is very powerful and used a lot by Apple. For instance the edit canvas in Pages is written almost exclusively usingCALayer
s.Shortest way to achieve this is probably to take the following steps:
UIView
drawRect
to provide your custom drawing for the viewdrawRect
, use theCore Graphics API
, which allows you to draw custom shapes on a drawing context, and offers functions such asrotation
orscaling
Here is an overview of the API from the Apple docs.